git 命令发出远程跟踪分支的名称
我想要一个命令来发出我所在分支的跟踪分支的名称。比如:
$ git checkout --track -b topic origin/master
Branch topic set up to track remote branch master from origin.
Switched to a new branch 'topic'
$ git unknown-command
origin/master
有这样的命令吗?
I'd like a command that emits the name of the tracked branch for the branch I'm on. Something like:
$ git checkout --track -b topic origin/master
Branch topic set up to track remote branch master from origin.
Switched to a new branch 'topic'
$ git unknown-command
origin/master
Is there such a command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据 Mark Longair 的要求,我之前的评论现在被转载为答案。
使用最新版本的 git,您可以使用 git rev-parse --symbolic-full-name @{u} 发出当前分支的远程跟踪分支的名称。它会发出类似 refs/remotes/origin/master 的内容。
如果您更进一步并使用
--abbrev-ref
标志,如git rev-parse --symbolic-full-name --abbrev-ref @{u},它会去掉 refs/remotes/
位,只留下简短的分支名称,例如origin/master
。As per Mark Longair's request, my previous comment is now reproduced as an answer.
With recent versions of git, you can emit the name of the remote-tracking branch for your current branch with
git rev-parse --symbolic-full-name @{u}
. It emits something like refs/remotes/origin/master.If you go one step further and use the
--abbrev-ref
flag, as ingit rev-parse --symbolic-full-name --abbrev-ref @{u}
, it will strip off therefs/remotes/
bit and leave you with just the short branch name, such asorigin/master
.将发出正在跟踪的遥控器:
将发出正在该遥控器上跟踪的引用:
我不相信有一个组合命令可以同时发出两者(至少在正常的 Git 中;你总是可以自己制作)。
例如,对于本地
master
分支:Will emit the remote being tracked:
Will emit the ref being tracked on that remote:
I don't believe that there is a combined command that will emit both together (at least within normal Git; you could always make your own).
For example, for a local
master
branch:从 git 1.8.3 开始,您现在可以这样做:
非常方便,因为它一次显示所有本地分支的跟踪分支,但它不适合编写脚本。
As of git 1.8.3 you can now do this:
Very convenient as it shows the tracking branch for all local branches at once, but it is not suitable for scripting.