jds*_*ion 932
这是一个命令,为您提供所有跟踪分支(配置为"拉"),请参阅:
$ git branch -vv
main aaf02f0 [main/master: ahead 25] Some other commit
* master add0a03 [jdsumsion/master] Some commit
Run Code Online (Sandbox Code Playgroud)
你必须浏览SHA和任何长包装提交消息,但是它可以快速输入,并且我会在第3列中垂直对齐跟踪分支.
如果您需要有关每个分支的"拉"和"推"配置的信息,请参阅另一个答案git remote show origin
.
更新
从git版本1.8.5开始,您可以使用git status
和显示上游分支git status -sb
cdu*_*001 355
两种选择:
% git rev-parse --abbrev-ref --symbolic-full-name @{u}
origin/mainline
Run Code Online (Sandbox Code Playgroud)
要么
% git for-each-ref --format='%(upstream:short)' "$(git symbolic-ref -q HEAD)"
origin/mainline
Run Code Online (Sandbox Code Playgroud)
Aji*_*rge 211
我想git branch -av
只会告诉你你有哪些分支以及它们在哪些提交,让你推断当地分支机构正在跟踪哪些远程分支.
git remote show origin
明确告诉您哪些分支正在跟踪哪些远程分支.这是来自具有单个提交和远程分支的存储库的示例输出abranch
:
$ git branch -av
* abranch d875bf4 initial commit
master d875bf4 initial commit
remotes/origin/HEAD -> origin/master
remotes/origin/abranch d875bf4 initial commit
remotes/origin/master d875bf4 initial commit
Run Code Online (Sandbox Code Playgroud)
与
$ git remote show origin
* remote origin
Fetch URL: /home/ageorge/tmp/d/../exrepo/
Push URL: /home/ageorge/tmp/d/../exrepo/
HEAD branch (remote HEAD is ambiguous, may be one of the following):
abranch
master
Remote branches:
abranch tracked
master tracked
Local branches configured for 'git pull':
abranch merges with remote abranch
master merges with remote master
Local refs configured for 'git push':
abranch pushes to abranch (up to date)
master pushes to master (up to date)
Run Code Online (Sandbox Code Playgroud)
Aar*_*lls 68
更新:嗯,我发布这个已经好几年了!为了我将HEAD与上游进行比较的具体目的,我现在使用@{u}
,这是一个引用上游跟踪分支的HEAD的快捷方式.(参见https://git-scm.com/docs/gitrevisions#gitrevisions-emltbranchnamegtupstreamemegemmasterupstreamememuem).
原始答案:我也遇到过这个问题.我经常在一个存储库中使用多个遥控器,很容易忘记当前分支跟踪的是哪一个.有时候知道这一点很方便,例如当你想看看你的本地提交时git log remotename/branchname..HEAD
.
所有这些东西都存储在git config变量中,但你不必解析git config输出.如果你调用git config后跟变量的名称,它只会打印该变量的值,不需要解析.考虑到这一点,这里有一些命令来获取有关当前分支的跟踪设置的信息:
LOCAL_BRANCH=`git name-rev --name-only HEAD`
TRACKING_BRANCH=`git config branch.$LOCAL_BRANCH.merge`
TRACKING_REMOTE=`git config branch.$LOCAL_BRANCH.remote`
REMOTE_URL=`git config remote.$TRACKING_REMOTE.url`
Run Code Online (Sandbox Code Playgroud)
在我的情况下,因为我只想找到我当前遥控器的名称,我这样做:
git config branch.`git name-rev --name-only HEAD`.remote
Run Code Online (Sandbox Code Playgroud)
nik*_*ypx 47
当地的分支机构和他们的遥控器.
git branch -vv
Run Code Online (Sandbox Code Playgroud)
所有分支机构和跟踪遥控器.
git branch -a -vv
Run Code Online (Sandbox Code Playgroud)
查看为推送和拉取显式配置本地分支的位置.
git remote show {remote_name}
Run Code Online (Sandbox Code Playgroud)
Sab*_*osh 24
git branch -vv | grep 'BRANCH_NAME'
git branch -vv
:这部分将显示所有本地分支及其上游分支。
grep 'BRANCH_NAME'
: 它将从分支列表中过滤当前分支。
rub*_*o77 19
这将显示您所在的分支:
$ git branch -vv
Run Code Online (Sandbox Code Playgroud)
这将仅显示您当前的分支:
$ git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)
Run Code Online (Sandbox Code Playgroud)
例如:
myremote/mybranch
Run Code Online (Sandbox Code Playgroud)
您可以找到当前分支所使用的远程 URL :
$ git remote get-url $(git for-each-ref --format='%(upstream:short)' $(git symbolic-ref -q HEAD)|cut -d/ -f1)
Run Code Online (Sandbox Code Playgroud)
例如:
https://github.com/someone/somerepo.git
Run Code Online (Sandbox Code Playgroud)
Eug*_*ash 18
您可以使用git checkout
,即"检查当前分支".这是一个带有副作用的无操作,用于显示当前分支的跟踪信息(如果存在).
$ git checkout
Your branch is up-to-date with 'origin/master'.
Run Code Online (Sandbox Code Playgroud)
Wil*_*ell 16
我不知道这是否算作解析git config的输出,但这将确定master正在跟踪的远程的URL:
$ git config remote.$(git config branch.master.remote).url
小智 11
还有另一种方式
git status -b --porcelain
Run Code Online (Sandbox Code Playgroud)
这会给你
## BRANCH(...REMOTE)
modified and untracked files
Run Code Online (Sandbox Code Playgroud)
Phi*_*bin 10
仅显示当前分支信息而不使用grep
:
git branch -vv --contains
Run Code Online (Sandbox Code Playgroud)
这是以下的缩写:
git branch -vv --contains HEAD
Run Code Online (Sandbox Code Playgroud)
如果您当前的 HEAD 提交 ID 在其他分支中,这些分支也会显示。
另一种方法(谢谢osse),如果你只是想知道它是否存在:
if git rev-parse @{u} > /dev/null 2>&1
then
printf "has an upstream\n"
else
printf "has no upstream\n"
fi
Run Code Online (Sandbox Code Playgroud)
git-status 瓷器(机器可读)v2 输出如下所示:
$ git status -b --porcelain=v2
# branch.oid d0de00da833720abb1cefe7356493d773140b460
# branch.head the-branch-name
# branch.upstream gitlab/the-branch-name
# branch.ab +2 -2
Run Code Online (Sandbox Code Playgroud)
并且只让分支上游:
$ git status -b --porcelain=v2 | grep -m 1 "^# branch.upstream " | cut -d " " -f 3-
gitlab/the-branch-name
Run Code Online (Sandbox Code Playgroud)
如果分支没有上游,上述命令将产生一个空输出(或失败set -o pipefail
)。
列出本地和远程分支:
$ git branch -ra
Run Code Online (Sandbox Code Playgroud)
输出:
feature/feature1
feature/feature2
hotfix/hotfix1
* master
remotes/origin/HEAD -> origin/master
remotes/origin/develop
remotes/origin/master
Run Code Online (Sandbox Code Playgroud)
如果您想找到任何分支的上游(而不只是您所在的分支),请对 @cdunn2001 的答案稍作修改:
git rev-parse --abbrev-ref --symbolic-full-name YOUR_LOCAL_BRANCH_NAME@{upstream}
这将为您提供名为 的本地分支的远程分支名称YOUR_LOCAL_BRANCH_NAME
。
你可以试试这个:
git remote show origin | grep "branch_name"
Run Code Online (Sandbox Code Playgroud)
branch_name
需要用你的分支替换
Pat*_*otz -5
我使用EasyGit(又名“eg”)作为 Git 之上(或旁边)的超轻量级包装器。EasyGit 有一个“info”子命令,可以为您提供各种超级有用的信息,包括当前分支远程跟踪分支。这是一个示例(其中当前分支名称是“foo”):
pknotz@s883422: (foo) ~/workspace/bd $ 例如信息 总提交数:175 本地存储库:.git 命名远程存储库:(名称 -> 位置) 来源 -> git://sahp7577/home/pknotz/bd.git 当前分支: foo 加密校验和 (sha1sum):bd248d1de7d759eb48e8b5ff3bfb3bb0eca4c5bf 默认拉/推存储库:origin 默认拉/推选项: 分支.foo.remote = 原点 branch.foo.merge = refs/heads/aal_devel_1 贡献者人数:3 文件数量:28 目录数量:20 最大文件大小(以字节为单位):32473(pygooglechart-0.2.0/COPYING) 提交次数:62
归档时间: |
|
查看次数: |
460191 次 |
最近记录: |