我只是在阅读git status文档(ver2.34.0),我发现了如下内容:
Line Notes
------------------------------------------------------------
# branch.oid <commit> | (initial) Current commit.
# branch.head <branch> | (detached) Current branch.
# branch.upstream <upstream_branch> If upstream is set.
# branch.ab +<ahead> -<behind> If upstream is set and the commit is present.
------------------------------------------------------------因此,从理论上讲,branch.upstream 和 branch.ab 都是在不同的条件下出现的,但从我的测试来看,它们总是同时出现。
有人能创造一个条件,其中只有branch.upstream 出现吗?谢谢!
发布于 2021-11-22 03:46:30
我将在这里就我对LeGEC的回答的评论做一些补充。
假设您有一个存储库:
$ cd <somewhere-with-repository>该存储库有一个远程名称,例如,origin,而remote有一些分支(Es)。我们现在执行您的git status --porcelain=v2以获得一个示例输出:
$ git status --porcelain=v2 -b
# branch.oid 2808ac68000c62c3db379d73e3b7df292e333a57
# branch.head master
# branch.upstream origin/master
# branch.ab +0 -0这个特定的存储库只有master和origin/master。
$ git branch -a
* master
remotes/origin/master因此,现在我们需要创建一个新的分支来触发您想要的条件:
$ git switch -c foo
Switched to a new branch 'foo'
$ git status --porcelain=v2 -b
# branch.oid 2808ac68000c62c3db379d73e3b7df292e333a57
# branch.head foo我们现在需要将上游设置为origin/foo,但git branch -u拒绝这样做:
$ git branch -u origin/foo
error: the requested upstream branch 'origin/foo' does not exist
hint:
hint: If you are planning on basing your work on an upstream
hint: branch that already exists at the remote, you may need to
hint: run "git fetch" to retrieve it.
hint:
hint: If you are planning to push out a new local branch that
hint: will track its remote counterpart, you may want to use
hint: "git push -u" to set the upstream config as you push.但是我们可以使用底层的branch.foo.remote和branch.foo.merge设置来解决这个问题:
$ git config branch.foo.remote origin
$ git config branch.foo.merge refs/heads/foo
# branch.oid 2808ac68000c62c3db379d73e3b7df292e333a57
# branch.head foo
# branch.upstream origin/foo使用git branch -vv向我们展示了以下内容:
$ git branch -vv
* foo 2808ac6 [origin/foo: gone] add xheap, for a priority queue for py3k
master 2808ac6 [origin/master] add xheap, for a priority queue for py3k这也是我们在git push -u origin foo中看到的,随后删除了origin/foo,这会修剪我们自己的refs/remotes/origin/foo。
(这有点奇怪,git branch -u不会让您直接设置这种情况,因为它将避免以后对git push -u的需求,因此在脚本中很有用。但是,低级的git config命令确实允许您设置这种情况。)
发布于 2021-11-21 16:53:07
你可以在上游设置一个分支:
git branch -u some/upstream如果你选择一个还不存在的上游(例如:git branch -u origin/doesnt/exist/yet),你应该选择“如果上游是设置的”。没有“.而且提交是存在的。”
编辑:实际上(正如@torek所指出的),git branch -u some/upstream将检查some/upstream是否存在,并且不允许您跟踪不存在的分支。
“分支跟踪”存储在存储库的配置中,您可以编辑配置文件强制设置不存在的远程分支:
[branch "test"]
remote = origin
merge = refs/heads/doesnt/exist然而,在实践中,你不会经常遇到这种情况。
您通常会通过诸如git checkout <origin/somebranch>或git push -u ...之类的命令设置分支跟踪,这两个命令都确保在创建或更新链接时存在“远程分支”。
如果某个远程分支被其他人删除,并且您的本地分支仍被设置为跟踪该远程分支,则可能发生这种情况。
https://stackoverflow.com/questions/70053952
复制相似问题