2016-11-23 210 views
1

我正在開發一個不同的機器,而不是我通常做的,似乎git的行爲與我記憶中的不同。git status和git diff空失敗後git我

當我籤一個新的分支git checkout -b <new branch name>,並嘗試應用補丁git am </path/to/file.patch>,補丁未申請:

</path/to/file.patch> 
Applying: <commit msg> 
error: patch failed: <filename>:<line no> 
error: <filename>: patch does not apply 
Patch failed at <commit msg> 
The copy of the patch that failed is found in: .git/rebase-apply/patch 
When you have resolved this problem, run "git am --continue". 
If you prefer to skip this patch, run "git am --skip" instead. 
To restore the original branch and stop patching, run "git am --abort". 

現在,我在我的其他機器發誓當補丁逾期不申請,git statusgit diff將顯示文件修改爲<<<HEAD>>>>標記,顯示我需要修復三路合併的位置。目前git status顯示我處於am操作的中間,但沒有更改文件,git diff也一樣。

我忘了還是我的其他機器可能有舊版本的git,甚至是不同的配置選項集?爲什麼git不顯示合併衝突?我需要設置一個mergetool嗎?我目前無法訪問我的其他機器,但我會嘗試在更新信息時更新此帖子。

編輯:

git am --3way似乎是我想要的。 [0] [1]但是git am --3way <path/to/patch>git config --global am.threeWay true似乎都不起作用。

啊,它的失敗與現在不同的信息:

</path/to/file.patch> 
Applying: <commit msg> 
fatal: sha1 information is lacking or useless (<filename>).   <-- new 
error: could not build fake ancestor         <-- new 
Patch failed at <commit msg> 
The copy of the patch that failed is found in: .git/rebase-apply/patch 
When you have resolved this problem, run "git am --continue". 
If you prefer to skip this patch, run "git am --skip" instead. 
To restore the original branch and stop patching, run "git am --abort". 

與之相似,git am --3way </path/to/patch>失敗:

error: patch failed: <file>:<lineno> 
error: repository lacks the necessary blob to fall back on 3-way merge. 
error: Makefile: patch does not apply 

也許這個補丁是不能贖回?採取patch -p1 < </path/to/path>適用於第一塊,並在第二塊失敗,所以我想我必須手工完成。

我應該注意到,我正在用--depth 1克隆的淺回購工作。

[0] https://www.kernel.org/pub/software/scm/git/docs/git-am.html [1] https://www.kernel.org/pub/software/scm/git/docs/git-config.html

回答

2

啊哈! This SO post led me to an answer.

兩個事情出錯:

設置三路合併爲git am默認行爲:

git config --global am.threeWay true

這是由事實混淆,我做了一個淺拷貝(即。 --depth 1)。我鏈接到的SO帖子解釋說,沒有足夠的歷史記錄,警告fatal: sha1 information is lacking or useless說「沒有足夠的信息構建三路合併」。

這將是在這種情況下,如果提到你做了一個淺拷貝來獲取更多的歷史很有幫助它混帳......

+0

本身肯定需要是強化的消息。我也會將'git fetch --unshallow'提示添加到我的其他答案中。 – torek