is it possible to display the latest commit when i use “git branch”?
Now, is there a way to display the latest commit on each branch when I enter “git branch -arg”? I find it a bit annoying/tedious to have to checkout each branch then check the commits using “git log”.
3 Solutions collect form web for “is it possible to display the latest commit when i use “git branch”?”
git branch -v lists branch names and the SHA and commit message of the latest commit on each branch.
See the git branch manual page.
Yes, you can add a post-checkout hook (described here).
Basically, create the
.git/hooks/post-checkout file and put whatever git command you want to run in it, and finally make sure to make that file executable (
chmod +x .git/hooks/post-checkout on unix-like systems, such as Mac OS, GNU/Linux, etc).
For example, if you put
git show in that file, it will automatically show you the last commit and what changes were made whenever you switch branch.
There are multiple
git log parameters to control its output:
--remotes to select which commits to show,
--no-walk to avoid showing all their history (just their tips as you want),
--oneline shows only the first line of commit logs,
--color=always add more eye candy 😀
Try these commands:
$ # show the first line of the commit message of all local branches $ git log --oneline --decorate --color=always --branches --no-walk $ # show the whole commit message of all the branches that start with "feature-" $ git log --decorate --color=always --branches='feature-*' --no-walk $ # show the last commit of all remote and local branches $ git log --decorate --color=always --branches --remotes --no-walk $ # show the last commit of each remote branch $ git fetch $ git log --decorate --color=always --remotes --no-walk
BTW, there’s no need to switch branches to see other branch’s commits:
$ # show the 'otherbranch' last commit message $ git log --decorate --color=always -n 1 otherbranch $ # show a cool graph of the 'otherbranch' history $ git log --oneline --decorate --color=always --graph otherbranch