7

因此,在每个分支上,如果我执行“git log”或“git lg”,它将显示已完成的提交列表。

现在,当我输入“git branch -arg”时,有没有办法在每个分支上显示最新提交?我发现必须检查每个分支然后使用“git log”检查提交有点烦人/乏味。

4

3 回答 3

12

git branch -v列出分支名称以及每个分支上最新提交的 SHA 和提交消息。

请参阅git 分支手册页

于 2012-07-17T14:11:42.827 回答
4

是的,您可以添加结帐后挂钩(在此处描述)。

基本上,创建.git/hooks/post-checkout文件并将您想要运行的任何 git 命令放入其中,最后确保使该文件可执行(chmod +x .git/hooks/post-checkout在类似 unix 的系统上,例如 Mac OS、GNU/Linux 等)。

例如,如果您放入git show该文件,它会自动向您显示最后一次提交以及在您切换分支时所做的更改。

于 2012-07-17T14:05:54.350 回答
2

有多个git log参数可以控制其输出:

--branches, --glob, --tag,--remotes选择要显示的提交,--no-walk避免显示所有历史记录(只是您想要的提示),--oneline仅显示第一行提交日志,--decorate--color=always添加更多吸引眼球的东西:D

试试这些命令:

$ # 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

顺便说一句,无需切换分支即可查看其他分支的提交:

$ # 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
于 2012-07-17T14:33:55.870 回答