Is it possible to display the last commit when I use the "git branch"?

So, on each branch, if I do "git log" or "git lg", it will show a list of completed commits.

Now, is there a way to show the last commit in each branch when I enter "git branch -arg"? I find it a little annoying / tedious to check each branch, then check commits using the "git log".

+4
source share
3 answers

git branch -v lists the git branch -v names and SHA and commit messages of the last commit in each branch.

See the git branch manual page .

+8
source

Yes, you can add a hook after checking ( described here ).

Basically create a .git/hooks/post-checkout file and put any git command you want to run in it, and finally make sure that this executable ( chmod +x .git/hooks/post-checkout in unix- similar systems such as Mac OS, GNU / Linux, etc.).

For example, if you put git show in this file, it will automatically show you the latest commit and what changes were made each time the branch was switched.

+3
source

There are several git log options for controlling the output:

Like --branches , --glob , --tag , --remotes to choose which captures, --no-walk , so as not to show your entire history (only their advice, as you want), --oneline only shows first line of commit logs, --decorate and --color=always add more eye candy: D

Try the following 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 

By the way, there is no need to switch branches to see other 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 
+1
source

All Articles