我只是在閱讀git status檔案(版本 2.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出現的條件嗎?謝謝!
uj5u.com熱心網友回復:
我將在這里擴展我對 LeGEC 回答的評論。
假設您有一個存盤庫:
$ cd <somewhere-with-repository>
并且該存盤庫具有遠程名稱,例如origin,并且遠程具有一些分支。我們現在做你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命令確實可以讓您設定這種情況。)
uj5u.com熱心網友回復:
您可以將上游設定為分支:
git branch -u some/upstream
如果 yostate 你選擇了一個尚不存在的上游(例如:)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://www.uj5u.com/ruanti/363602.html
標籤:混帐
下一篇:Git子模塊更新卡在舊提交上
