我有一个看起来像这样的git别名:
[alias]
unpushed = log origin..HEAD --pretty=format:'%h %an %s'
Run Code Online (Sandbox Code Playgroud)
当我在掌握时,这对于显示"未按下"的变化非常有用.但是,当我在分支机构时,这个别名并不能正常工作.
无论我是否在分支上,正确的命令是什么才能显示未按下的更改?
如果您只想查看当前分支的传出提交,可以使用以下命令:
git config alias.unpushed "log @{u}.. --pretty=format:'%h %an %s'"
Run Code Online (Sandbox Code Playgroud)
这导致git log显示从HEAD排除从上游分支可到达的所有提交到达的提交.该@{u}..参数等同于@{u}..HEAD,并且@{u}是当前分支的上游提交的简写(例如,origin/foo如果签出的分支是foo).
如果要查看所有分支的所有未提交的提交,请执行以下操作:
git config alias.unpushed "log --all --not --remotes --tags --pretty=format:'%h %an %s'"
Run Code Online (Sandbox Code Playgroud)
以上原因导致git log遍历所有引用,但停止(排除)远程引用(例如origin/master)和标记.Git不区分本地和远程标签,因此上面假设所有标签都是远程的(这并不总是正确的,因此您可能希望--tags有时忽略参数).
我个人使用以下别名来显示未提交的提交:
# unpushed: graph of everything excluding pushed/tag commits
# with boundary commits (see below for 'git g' alias)
git config alias.unpushed '!git g --not --remotes --tags'
# go: _G_raph of _O_utgoing commits with boundary commits
# (see below for 'git gb' alias)
git config alias.go '!git gb @{u}..'
# g: _G_raph of everything with boundary commits
git config alias.g '!git gb --all'
# gb: _G_raph of current _B_ranch (or arguments) with boundary commits
git config alias.gb '!git gbnb --boundary'
# gbnb: _G_raph of current _B_ranch (or arguments) with _N_o _B_oundary commits
git config alias.gbnb 'log --graph --date-order --pretty=tformat:"%C(yellow)%h%Creset %C(magenta)%aE %ai%Creset %C(green bold)%d%Creset%n %s"'
Run Code Online (Sandbox Code Playgroud)
对于简单的存储库,我使用git g别名作为探索提交的主要方法.对于复杂的存储库(几十个分支),我通常git gb用来显示特定的分支或提交范围.当我想看看如何git push更改远程引用(我push.default的设置为upstream)时,我会使用git go.当我想看看我的本地存储库中是否有任何东西时我没有推动(例如,如果我删除了克隆,看看我是否会失去工作),我使用git unpushed.