可以提交包含衝突數據的文件。有沒有辦法標記這些文件再次發生衝突,以便運行git mergetool將生成必要的文件並運行合併工具?有沒有辦法讓Git將文件標記爲衝突?
回答
您可以使用git checkout --conflict=merge -- file
獲取衝突標記文件的內容,但是如果您已使用git add file
(或者如果GUI爲您做了這些)清除了索引,則它不起作用。
有git update-index --unresolve
,但它是hacky,並不能非常可靠地工作。我認爲它恢復的狀態對於git-mergetool是不夠的。
您可能需要重做合併,或者使用git update-index --cacheinfo
來手動設置階段版本...... git-stash可以幫助您正確保存已解決的衝突。
據我所知,當文件中仍然包含衝突標記時,您將無法提交。 ......這是不完全正確:
的OP提到,你可以(我複製到這裏his pastbin),但不會有足夠的合併工具再次被觸發:
Auto-merged README
CONFLICT (content): Merge conflict in README
Automatic merge failed; fix conflicts and then commit the result.
lynx:~/test_clone$ ls
README
lynx:~/test_clone$ git add README
lynx:~/test_clone$ git commit -a
Created commit 46ee062: It works!
lynx:~/test_clone$ ls
README
lynx:~/test_clone$ cat README
<<<<<<< HEAD:README
testingtesting
=======
hmm
>>>>>>> 881d60f5f738bc5716f5c9a9384e262b535717fd:README
lynx:~/test_clone$
由於Charles Bailey評論,並示出在本SO answer,的合併工具被查詢,因爲有在索引同一文件的3個實例:
對於在衝突的git毫安一個未合併文件kes提供索引中文件的通用基礎,本地和遠程版本。 (這是他們從一個三路比較工具使用的
git mergetool
閱讀。)你可以使用git節目進行查看:
# common base:
git show :1:afile.txt
# 'ours'
git show :2:afile.txt
# 'theirs'
git show :3:afile.txt
git add
(與任何內容,包括衝突標記)會自動刪除其中的2個,確保mergetool
不會再次調用。
確實可以。僅僅通過git add
@Christian:有趣的(我已經修改了答案以反映它),但git mergetool會檢測到它並重新觸發合併? – VonC 2010-05-06 18:14:40
如果git在索引中有多個條目,而不僅僅是通常的條目,git會確定文件發生衝突。 git在工作樹版本中放置衝突標記以幫助用戶解決衝突,但這些並不是git將文件計入未裝入的。調用git add告訴git將文件的工作樹版本添加到索引_removing所有其他entries_。在git添加之後,因爲現在只有一個索引條目,文件不再是'未解析的',因此您可以提交它。 – 2010-05-06 21:56:50
@VonC:我最初沒有創建帳戶(我現在有),所以我無法發表評論。 調用git的合併工具不檢測到它,它似乎:
Auto-merged README CONFLICT (content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result. lynx:~/test_clone$ ls README lynx:~/test_clone$ git add README lynx:~/test_clone$ git commit -a Created commit 46ee062: It works! lynx:~/test_clone$ ls README lynx:~/test_clone$ cat README >>>>>> 881d60f5f738bc5716f5c9a9384e262b535717fd:README lynx:~/test_clone$ git mergetool merge tool candidates: opendiff emerge vimdiff No files need merging lynx:~/test_clone$
混帳合併工具可以接受一個文件名,但是,這並不工作,要麼:這裏
Auto-merged README CONFLICT (content): Merge conflict in README Automatic merge failed; fix conflicts and then commit the result. caracal:~/test_clone2$ git mergetool merge tool candidates: opendiff emerge vimdiff Merging the files: README Normal merge conflict for 'README': {local}: modified {remote}: modified Hit return to start merge resolution tool (emerge): caracal:~/test_clone2$ ls #*merge*#145962bz# README README~ README.orig caracal:~/test_clone2$ git mergetool merge tool candidates: opendiff emerge vimdiff No files need merging caracal:~/test_clone2$ git mergetool README merge tool candidates: opendiff emerge vimdiff README: file does not need merging caracal:~/test_clone2$ ls #*merge*#145962bz# README README~ README.orig caracal:~/test_clone2$
還請注意,我沒有提交後退出git mergetool。
在Charles的評論之後剛剛完成了我的回答。 – VonC 2010-05-07 04:16:48
s/lynx:。* \ $/\ n#/ g – user1133275 2017-05-29 16:24:56
最優雅的解決辦法是,以防止這個問題從一開始:
git config --global mergetool.[tool].cmd [command-line call]
git config --global mergetool.[tool].trustExitCode false
請使用git update-index --unresolve
由於混帳1。7它使用索引中的resolve-undo信息來恢復所有3個階段(1:基數,2:我們的,3:他們的):https://github.com/git/git/commit/8aa38563b22c84b06ea1fff9638cc1f44fda726f
如果索引已經處於衝突狀態,只需檢出文件在--conflict=merge
標誌:
git checkout --conflict=merge file
如果該指數是乾淨的,因爲懸而未決的文件已被[誤]添加,檢查出來之前剛剛復位:
git reset file
git checkout --conflict=merge file
這將允許你繼續解決衝突通常(例如,git mergetool
)。
備註:通過@fourpastmidnight的請求,將@ jakub-narębski的回答推薦到自己的答案中。 :)
- 1. 在Git中,有沒有辦法將文件標記爲「純」?
- 2. 在Git中,有沒有辦法自動將合併衝突中的所有新文件標記爲正確?
- 3. git標記爲衝突的所有文件
- 4. 有沒有辦法關閉git衝突解決?
- 5. TortoiseSVN的文件標記爲衝突的,但沒有衝突可能是TortoiseMerge
- 6. 更改git衝突標記
- 7. 有沒有辦法將標記作爲schema.org itemprop的值?
- 8. 有沒有辦法將cookies標記爲HttpOnly在主塔中?
- 9. 有沒有辦法將NSManagedObject標記爲髒?
- 10. SVN標記整個文件爲衝突
- 11. 有沒有辦法讓jQuery輸出*實際標記*?
- 12. 有沒有辦法讓git獲取並且只獲取歷史記錄 - 沒有文件
- 13. Git合併不標記衝突文本文件中的所有差異
- 14. 沒有衝突的git推送失敗
- 15. 名稱衝突 - 是有沒有辦法阻止它
- 16. Git ID沒有顯示任何二進制文件衝突
- 17. 意外的顛覆衝突行爲(衝突沒有衝突)
- 18. 有沒有辦法在沒有衝突的窗口上註冊熱鍵?
- 19. 有沒有辦法爲SWT組件啓用雙緩衝?
- 20. Git如何從文件中刪除衝突標記?
- 21. 有沒有辦法讓git diff顯示的行發生變化?
- 22. 有沒有辦法讓git pull自動更新子模塊?
- 23. git rebase和文件衝突
- 24. 共享git文件衝突
- 25. 有沒有辦法讓Mathematica將符號視爲真實?
- 26. 有沒有辦法在Windows中保存vim中的文件而不將其標記爲可執行文件?
- 27. 有沒有辦法將Linux管道設置爲非緩衝或線路緩衝?
- 28. 拆分帶有衝突標記的文件
- 29. 有沒有辦法讓git cherry-pick無需處理標籤污染
- 30. 有沒有辦法將兩個gcov文件合併爲一個
嘿,我只是寫了這個回覆。 ;-) – ebneter 2010-05-07 01:24:27
什麼是hacky和不可靠的呢? – 2010-05-10 12:52:00
'git update-index --unresolve'是在「古代」時代創建的,以允許在確認衝突解決之後(意外)'git add'恢復'git diff --ours'等。它在階段#2填充HEAD版本(不包括解決了自動解決的衝突的版本),在階段#3填充MERGE_HEAD版本,並且不在階段#1中放入任何東西,即祖先版本。 – 2010-05-10 21:37:20