无论提交什么分支,都可以使用别名进行提交吗?

问题描述:

我有一个git的别名,看起来像这样:无论提交什么分支,都可以使用别名进行提交吗?

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

伟大的工程为显示当我在主“unpushed”的转变。但是,当我在一个分支上时,这个别名并没有真正的工作。

无论我是否在分支上,正确的命令是什么将显示unpushed更改?

+0

似乎在分支上工作好吗...什么不适合你? –

+0

它有效,但它显示了分支如何与主分离,而不是我的本地副本如何与上游分离,这正是我想要的。 – slacy

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

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

这将导致git log显示所有提交可达来自HEAD不包括到达从上游分支。 @{u}..参数相当于@{u}..HEAD,而@{u}是当前分支上游提交的简写(例如,如果检出分支是foo,则为origin/foo)。

如果你想看到所有分支都unpushed提交,这样做:

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

上述原因git log走路的所有引用,但在(不含)的远程引用(例如,origin/master)和标签停止。 Git不区分本地和远程标签,所以上面假设所有标签都是远程的(这并不总是如此,所以你可能有时候会忽略掉--tags)。

我个人使用下面的别名显示unpushed提交:

# 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

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

这就能做到:

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

它比较上游跟踪分支(例如refs/remotes/origin/master)与头部的全名。全名是您平均git操作的有效参考。

如果使用fetch代替pull,想犯要么分支但不能同时使用...语法,而不是在命令..语法。

+0

工程,但并没有真正的工作 - 这个广告是检出树的别名。gitconfig,但如果我使用“git checkout”切换分支,别名将继续引用旧的分支。你不能在〜/ .gitconfig中放入“$(git ...)”风格的shell扩展,这正是我想要的。 – slacy

+0

@slacy嗯,我现在看到了错误。 upvoted理查德的答案。 – Christopher