git 中的这个分支跟踪(如果有的话)是什么?
使用 --track (或保留默认值或 --notrack)创建分支后,您稍后希望得到提醒分支正在跟踪的内容。除了搜索 .git/config 文件之外,还有其他方法可以显示分支正在跟踪的内容吗?
After creating a branch with --track (or leaving the default, or --notrack), you later wish to be reminded of what a branch is tracking. Is there a way, other than searching through the .git/config file, to display what a branch is tracking?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
使用: gitbranch -vv 来查看哪些分支被跟踪,哪些没有被跟踪。
Use:
git branch -vv
to see which branches are tracked and which are not.请注意, git1.8.3 (4 月22d, 2013),你有一种新的方式来强调上游分支:
Note that with git1.8.3 (April 22d, 2013), you have a new way to emphasize the upstream branch:
如果您想知道给定的分支,您可以这样做:
如果它打印远程,则它正在跟踪某些内容。如果它什么也不打印并返回失败,则不是。
If you want to know for a given branch, you could do:
If it prints a remote, it's tracking something. If it prints nothing and returns failure, it's not.
如果您需要以自动方式访问此信息,您将希望避免尝试解析
branch -vv
的输出 (slebetman 的答案)。Git 提供了一组具有稳定接口和输出格式的低级命令。这些命令(称为“管道”)是用于“脚本”目的的首选接口。 git for-each-ref 命令可以通过
upstream
令牌提供所需的信息(在 Git 1.6.3 及更高版本中提供):If you need to access this information in an automated fashion you will want to avoid trying to parse the output of
branch -vv
(slebetman’s answer).Git provides a set of lower-level commands with stable interfaces and output formats. These commands (called “plumbing”) are the preferred interface for ‘scripting’ purposes. The git for-each-ref command can provide the required information via the
upstream
token (available in Git 1.6.3 and later):感谢您的提示 Jefromi
使用以下命令,您可以获取特定分支的远程跟踪分支。
要更改远程跟踪分支,您只需更改此配置值即可。
注意:这是 gitbranch -vv 的替代方法(已在此处回答)
和 gitbranch -u (Make现有的 Git 分支跟踪远程分支?)
Thanks for the hint Jefromi
With the following command you can get the remote tracking branch for a specific branch.
To change the remote tracking branch you can simply change this config value.
Note: this is an alternative way to
git branch -vv
(already answered here)and
git branch -u
(Make an existing Git branch track a remote branch?)