Jer*_*use 200
以我从 Github.com 上的上游 Git 存储库中检出的 Puppet 副本为例...
$ git remote show origin
* remote origin
Fetch URL: git://github.com/reductivelabs/puppet.git
Push URL: git://github.com/reductivelabs/puppet.git
HEAD branch: master
Remote branches:
0.24.x tracked
0.25.x tracked
2.6.x tracked
master tracked
next tracked
primordial-ooze tracked
reins-on-a-horse tracked
testing tracked
testing-17-march tracked
testing-18-march tracked
testing-2-april tracked
testing-2-april-midday tracked
testing-20-march tracked
testing-21-march tracked
testing-24-march tracked
testing-26-march tracked
testing-29-march tracked
testing-31-march tracked
testing-5-april tracked
testing-9-april tracked
testing4268 tracked
Local branch configured for 'git pull':
master merges with remote master
Local ref configured for 'git push':
master pushes to master (up to date)
Run Code Online (Sandbox Code Playgroud)
然后,如果我要执行以下操作:
$ git checkout -b local_2.6 -t origin/2.6.x
Branch local_2.6 set up to track remote branch 2.6.x from origin.
Switched to a new branch 'local_2.6'
Run Code Online (Sandbox Code Playgroud)
最后再次重新运行git remote show origin命令,我将在底部附近看到以下内容:
Local branches configured for 'git pull':
local_2.6 merges with remote 2.6.x
master merges with remote master
Run Code Online (Sandbox Code Playgroud)
小智 129
对于所有分支机构:
git branch -avv
Run Code Online (Sandbox Code Playgroud)
只限本地分行:
git branch -lvv
Run Code Online (Sandbox Code Playgroud)
仅适用于远程分支:
git branch -rvv
Run Code Online (Sandbox Code Playgroud)
显示所有分支以及上游分支的名称。
Chr*_*sen 53
Jeremy Bous 说明了如何git remote show显示跟踪信息。如果您只想要供人类消费的信息,那应该就足够了。
如果您计划在自动化上下文(例如脚本)中使用信息,则应改用较低级别(“管道”)git for-each-ref。
% git remote show origin
* remote origin
?
Local branches configured for 'git pull':
master merges with remote master
pu merges with remote pu
?
% git for-each-ref --format='%(refname:short) <- %(upstream:short)' refs/heads
master <- origin/master
pu <- origin/pu
Run Code Online (Sandbox Code Playgroud)
该git for-each-ref学会的%(upstream)令牌的Git 1.6.3。对于早期版本的 Git,您必须使用git config branch.<name>.remote和提取跟踪信息git config branch.<name>.merge(可能git for-each-ref用于为每个本地分支名称构建命令)。
小智 19
对于特定的分支,可以使用git rev-parse与@{u}或@{upstream}在树枝上的名称,如后缀:
$ git rev-parse --symbolic-full-name master@{u}
refs/remotes/github-mhl/master
Run Code Online (Sandbox Code Playgroud)
... 或者对于缩写形式,添加 --abbrev-ref
$ git rev-parse --symbolic-full-name --abbrev-ref master@{u}
github-mhl/master
Run Code Online (Sandbox Code Playgroud)
您通常可以branch@{upstream}在需要提交的任何地方使用该语法。
Ing*_*kat 11
我使用以下 shell 脚本(名为git-tracks)来显示当前分支跟踪的远程分支:
#!/bin/sh -e
branch=$(git symbolic-ref HEAD)
branch=${branch##refs/heads/}
remote=$(git config "branch.${branch}.remote")
remoteBranch=$(git config "branch.${branch}.merge")
remoteBranch=${remoteBranch##refs/heads/}
echo "${remote:?}/${remoteBranch:?}"
Run Code Online (Sandbox Code Playgroud)
这也可以使用提到的git for-each-ref,但我发现直接访问比过滤当前分支的输出更简单。
小智 8
.git/config 文件还将提供跟踪分支信息作为
[remote "Hub"]
url = ssh://xxxx/tmp/Hub
fetch = +refs/heads/*:refs/remotes/Hub/*
[branch "develop"]
remote = Hub
merge = refs/heads/develop
[branch "Dev1"]
remote = Test
merge = refs/heads/Dev1
[remote "Test"]
url = ssh://xxxx/tmp/gittesting/Dev1GIT
fetch = +refs/heads/*:refs/remotes/Test/*
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
152663 次 |
| 最近记录: |