git 中的这个分支跟踪(如果有的话)是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3631706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:33:06  来源:igfitidea点击:

What is this branch tracking (if anything) in git?

gitbranchgit-branch

提问by Vincent Scheib

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?

在使用--track(或保留默认值,或--notrack)创建分支后,您稍后希望被提醒分支正在跟踪什么。除了搜索 .git/config 文件之外,有没有办法显示分支正在跟踪的内容?

回答by slebetman

Use: git branch -vvto see which branches are tracked and which are not.

用途:git branch -vv查看哪些分支被跟踪,哪些没有。

回答by VonC

Note that with git1.8.3 (April 22d, 2013), you have a new way to emphasize the upstream branch:

请注意,使用git1.8.3 (April 22d, 2013),您有一种强调上游分支的新方法:

"git branch --vv" learned to paint the name of the branch it integrates with in a different color (color.branch.upstream, which defaults to blue).

" git branch --vv" 学会了用不同的颜色 ( color.branch.upstream,默认为蓝色)绘制它所集成的分支的名称。

C:\prog\git\git>git branch -vv
* master 118f60e [origin/master] Sync with maint
                  ^^^^^^^^^^^^^
                       |
                       --- now in blue

回答by Cascabel

If you want to know for a given branch, you could do:

如果你想知道一个给定的分支,你可以这样做:

git config --get branch.<branch>.remote

If it prints a remote, it's tracking something. If it prints nothing and returns failure, it's not.

如果它打印遥控器,则它正在跟踪某些东西。如果它不打印任何内容并返回失败,则不是。

回答by Chris Johnsen

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).

如果您需要以自动方式访问此信息,您将希望避免尝试解析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-refcommand can provide the required information via the upstreamtoken (available in Git 1.6.3 and later):

Git 提供了一组具有稳定接口和输出格式的低级命令。这些命令(称为“管道”)是用于“编写脚本”目的的首选界面。所述的for-each-REF的git命令可以通过提供所需的信息upstream的令牌(可在GIT中1.6.3和更高版本):

% git for-each-ref --shell --format='

b=%(refname:short) u=%(upstream:short)
# Make a fancy report or do something scripty with the values.
if test -n "$u"; then
  printf "%s merges from %s\n" "$b" "$u" 
else
  printf "%s does not merge from anything\n" "$b" 
fi

' refs/heads/ | sh
master merges from origin/master
other does not merge from anything
pu merges from origin/pu

回答by nickel715

Thanks for the hint Jefromi

感谢您的提示Jefromi

With the following command you can get the remote tracking branch for a specific branch.

使用以下命令,您可以获得特定分支的远程跟踪分支。

git config --get branch.<branch>.merge

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?)

注意:这是git branch -vv(已在此处回答)
git branch -u使现有 Git 分支跟踪远程分支?)的替代方法