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

发布于 2024-09-18 05:27:33 字数 105 浏览 3 评论 0原文

使用 --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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

终难遇 2024-09-25 05:27:33

使用: gitbranch -vv 来查看哪些分支被跟踪,哪些没有被跟踪。

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

清欢 2024-09-25 05:27:33

请注意, git1.8.3 (4 月22d, 2013),你有一种新的方式来强调上游分支:

gitbranch -vv”学会了用不同的颜色绘制与其集成的分支的名称(color.branch.upstream,默认为蓝色)。

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

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

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

C:\prog\git\git>git branch -vv
* master 118f60e [origin/master] Sync with maint
                  ^^^^^^^^^^^^^
                       |
                       --- now in blue
時窥 2024-09-25 05:27:33

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

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

如果它打印远程,则它正在跟踪某些内容。如果它什么也不打印并返回失败,则不是。

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.

茶色山野 2024-09-25 05:27:33

如果您需要以自动方式访问此信息,您将希望避免尝试解析 branch -vv 的输出 (slebetman 的答案)。

Git 提供了一组具有稳定接口和输出格式的低级命令。这些命令(称为“管道”)是用于“脚本”目的的首选接口。 git for-each-ref 命令可以通过 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

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

% 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
疑心病 2024-09-25 05:27:33

感谢您的提示 Jefromi

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

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

要更改远程跟踪分支,您只需更改此配置值即可。

注意:这是 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.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文