因此,在每个分支上,如果我执行“git log”或“git lg”,它将显示已完成的提交列表。
现在,当我输入“git branch -arg”时,有没有办法在每个分支上显示最新提交?我发现必须检查每个分支然后使用“git log”检查提交有点烦人/乏味。
git branch -v
列出分支名称以及每个分支上最新提交的 SHA 和提交消息。
请参阅git 分支手册页。
是的,您可以添加结帐后挂钩(在此处描述)。
基本上,创建.git/hooks/post-checkout
文件并将您想要运行的任何 git 命令放入其中,最后确保使该文件可执行(chmod +x .git/hooks/post-checkout
在类似 unix 的系统上,例如 Mac OS、GNU/Linux 等)。
例如,如果您放入git show
该文件,它会自动向您显示最后一次提交以及在您切换分支时所做的更改。
有多个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