2017-06-22 109 views
1

在我的遠程存儲庫上創建了一個新的分支。在我的工作目錄(主分支)上的GitBash中,輸入git remote updategit pull。據我瞭解git remote update將更新所有分支機構設置爲這裏解釋追蹤遠程的: What is the difference between 'git remote update', 'git fetch' and 'git pull'?git分支unkown,但結帳工作

所以,當我鍵入git diff master newBranch --name-only我希望看到這是在兩個分支不同的文件列表。而是我得到了以下錯誤消息:

fatal: ambiguous argument 'newBranch': unknown revision or path not in the working tree.

但如果我鍵入git checkout newBranch它工作正常,如果我通過鍵入git checkout master突然git diff master newBranch --name-only作品完美地切換回主?

任何人都可以向我解釋這種行爲嗎?

回答

1

至於你提到你沒有分支「newBranch」的本地副本,所以你需要指定你想從遠程這樣做的分支標籤的DIFF:

git diff origin/master origin/newBranch --name-only 

或者假設你有本地主:

git diff master origin/newBranch --name-only 

檢查你有哪些地方分支:

git branch -l 

個或

git branch 

檢查遠程分支機構

git branch -r 

檢查所有分支:

git branch -a 

因此,這爲你工作,你做了結賬後,由於git的自動創建了一個名爲newBranch一個地方分支。所以在你的結賬git branch不會顯示一個名爲「newBranch」的分支,但結賬後它會。

1

當您第一次鍵入git diff master newBranch --name-only時,您沒有任何本地newBranch分支。因此,它給人的錯誤:

fatal: ambiguous argument 'newBranch': unknown revision or path not in the working tree.

後來,當你通過git checkout newBranch命令檢出到newBranch,創建一個新的本地分支。所以,下次git diff master newBranch --name-only也在工作。

注意:git checkout newBranch實際上找到一個本地newBranch分支,如果找到然後切換到分支。但是,如果找不到,則在遠程分支列表中找到,如果找到,則創建一個新的本地newBranch分支,跟蹤遠程newBranch分支。