对于未提交的提交的别名,无论我在哪个分支?

时间:2012-09-07 21:17:22

标签: git git-log

我有一个看起来像这样的git别名:

[alias]
        unpushed = log origin..HEAD --pretty=format:'%h %an %s'

非常适合展示"未按下"我在主人身上的变化。但是,当我在一个分支上时,这个别名并不能正常工作。

无论我是否在某个分支上显示未按下的更改,正确的命令是什么?

3 个答案:

答案 0 :(得分:5)

如果您只想查看当前分支的传出提交,可以使用以下命令:

git config alias.unpushed "log @{u}.. --pretty=format:'%h %an %s'"

这会导致git log显示从HEAD可到达的所有提交,但不包括从上游分支可到达的提交。 @{u}..参数等同于@{u}..HEAD@{u}是当前分支的上游提交的简写(例如,origin/foo,如果签出的分支是foo

如果要查看所有分支的所有未提交的提交,请执行以下操作:

git config alias.unpushed "log --all --not --remotes --tags --pretty=format:'%h %an %s'"

以上原因导致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"'

对于简单的存储库,我使用git g别名作为探索提交的主要方法。对于复杂的存储库(几十个分支),我通常使用git gb来显示特定的分​​支或提交范围。当我想知道git push将如何更改远程引用(我的push.default设置为upstream)时,我会使用git go。当我想查看本地存储库中是否有任何内容时,我没有推送(例如,如果我删除克隆,看看我是否会丢失工作),我使用git unpushed

答案 1 :(得分:1)

我使用git-wtf来解决此问题和其他问题。

答案 2 :(得分:1)

这样做:

git config alias.unpushed "log $(git rev-parse --symbolic-full-name @{u})..HEAD --pretty=format:'%h %an %s'"

它将上游跟踪分支的全名(例如refs/remotes/origin/master)与HEAD进行比较。全名是您的平均git操作的有效refspec。

如果您使用fetch代替pull,并希望在 分支中提交,但不想同时使用,请使用...语法而不是..命令中的语法。