iCodeLikeImDrunk
iCodeLikeImDrunk

Reputation: 17836

is it possible to display the latest commit when i use "git branch"?

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

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".

Upvotes: 9

Views: 5764

Answers (4)

Abdull
Abdull

Reputation: 27842

If not explicitly requested, git branch ... will only show local branches.

The -a option will show local as well as remote-tracking branches.

Also useful: when using the double-verbose -vv option, the output will additionally show for each local branch the relationship to its remote target branch, if such relationship exists:

git branch -avv

(official git-branch documentation)

Upvotes: 0

KurzedMetal
KurzedMetal

Reputation: 12946

There are multiple git log parameters to control its output:

Like --branches, --glob, --tag, --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, --decorate and --color=always add more eye candy :D

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

Upvotes: 3

georgebrock
georgebrock

Reputation: 30073

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.

Upvotes: 13

Frost
Frost

Reputation: 11957

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.

Upvotes: 4

Related Questions