Last Updated: January 20, 2017
·
16.91K
· compnerd

Branch history in Git

It is often useful to see what changes have been made in a particular branch when using git. The --cherry option to git log is very useful in that scenario. --cherry will show only the changes made on the "right" branch, indicating commits which have been applied to the "left" branch, even if the treeish is different.

git log --cherry master..branch

This command will show all the changes that have been made to the branch branch starting from a common ancestor in master, highlighting changes which have already been applied on master.

To make this command even more useful when reviewing the changes on a branch, it is possible to use the oneline description of the changes with an ASCII art representation of the flow of changes.

git log --cherry --oneline --graph master..branch

If you find yourself using this command quite frequently, it is extremely easy to create an alias for it.

git config --global alias.history "log --cherry --online --graph"

I find a bit more verbose log to be helpful and have embellished the alias as in the following command.

git config --global alias.history "log --cherry --boundary --decorate --color --oneline --graph"