Espen Henriksen
Front-end team lead
Oslo Market Solutions
espen_dev
esphen
Git 301
Advanced Git techniques
Git can be messy
Improve your toolbox
- If you only know git add, git commit and git merge, this talk is for you
- Git is a massive beast
- Extending your toolbox will pay off in the long run
- Use man pages
- f. ex. git bisect --help
- Ask if you're in trouble!
Inspecting commit history
git log --graph
git log --stat
You can even combine them
git log --stat --graph --oneline
Inspect other branches without checking them out
git show [<object>...]
Commiting
Commits
- Separate subject from body with a blank line
- Limit the subject line to 50 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line
- Wrap the body at 72 characters
- Use the body to explain what and why vs. how
- https://chris.beams.io/posts/git-commit
Summarize changes in around 50 characters or less
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequences of this
change? Here's the place to explain them.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
If you use an issue tracker, put references to them at the bottom,
like this:
Resolves: #123
See also: #456, #789
Git add -p
Use a different editor
Reverting merges
git revert --mainline
Git cherry-pick
Git cherry-pick <commit>...
Changing history
Git rebase master
Squashing commits
git rebase -i HEAD~2
Squash in a GitLab merge
Git push --force
Binary search with bisect
Find "Good" commit
Start bisecting
Test commit, mark as "Good" or "Bad"
Fin
Questions?
https://slides.com/esphen/advanced-git
Advanced Git Techniques
By Eline H
Advanced Git Techniques
- 20