git.day/9 • See all at git.day
Making sense of complicated Git histories that haven't been appropriately rebased can be difficult. Log options previously discussed, --oneline
and --graph
, help make history easier to follow. Another useful option to use on is --first-parent
.
When using Git with a pull request model and creating merge commits on the main branch, the commits on the branch for the pull request still show in the log. This is great preserving the history and making detail available for the changes made. However, if this branch was not created appropriately with a mess of commits, this can be hard to navigate through.
Using git log --first-parent
, only those merge commits to the main branch are shown. When combined with --oneline
and --graph
, this is the effect:
Git of the day #4: git log --oneline --graph
* PR3
|\
| * wijoe
| * pwoev
|/
* PR2
|\
| * vnawo
|/
* PR1
|\
| * bojiz
|/
* root
git log --oneline --graph --first-parent
* PR3
* PR2
* PR1
* root
This only works if merges are done keeping the first parent correct without reverse merging. Don't reverse merge main into your pull request branch — use Git of the day #5: git rebase --interactive instead!