簡體   English   中英

git:如何重做合並沖突解決方案(在提交合並之前)?

[英]git: How to redo a merge conflict resolution (before committing the merge)?

我做了一個

git merge FETCH_HEAD

並且,在 git 告訴我一個文件中存在沖突之后,我做了一個

git mergetool

在我的情況下,它運行 SourceGear DiffMerge 作為 GUI 合並工具。 保存合並文件后,我立即意識到我犯了一個嚴重的錯誤。 我只想忘記合並並重新開始。

由於我還沒有執行“git add”,更不用說提交任何東西了,我想我可以像這樣輕松地消除我的錯誤並重做合並:

git reset FILENAME
git merge FETCH_HEAD
git mergetool

這不起作用。 這個時候“git merge”告訴我

fatal: You have not concluded your merge (MERGE_HEAD exists).
Please, commit your changes before you can merge.

但當然,我不想提交搞砸的合並。 “git mergetool”抱怨

No files need merging

我想我在“git reset”命令上犯了一個錯誤。 這樣做的正確方法是什么?

添加:

我做了

git merge --abort

然后再次:

git merge FETCH_HEAD

這產生了

error: Your local changes to the following files would be overwritten by merge: ...

git status

說:

On branch ....
Your branch is up-to-date with ......
Changes not staged for commit:
    modified:   nVP.ini
Untracked files:
    nVP.ini.orig
no changes added to commit (use "git add" and/or "git commit -a")

只是一個想法:簡單地對 nVP.ini 進行 git checkout 是否會恢復合並前的情況?

要在提交之前撤消錯誤的沖突解決方案,請git checkout -m -- $thefile

$ git merge 3fac3
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
$ vi file.txt         # fix all the conflicts. do it wrong.
$ git add file.txt    # <--- ooops
$ git checkout -m -- file.txt    # <--- the correct un-oops-ifier here

並且file.txt返回到 failed-automerge 狀態。

請注意,您還可以指定沖突報告樣式,因此如果您通常使用默認的兩個差異樣式,但您有一個莫名其妙的樣式並且也想查看原始樣式,則可以這樣做

git checkout -m --conflict diff3 -- file.txt

我遇到過同樣的問題,

在 dev 中合並了一個分支,這在沖突解決期間擦除了另一個分支更改。

我為此使用了cherry-pick:

git cherry-pick {merge commit sha of missing branch code} -m 1

我能夠重做整個沖突解決過程。

jthill 的回答正是我想要的,但我想我想指出的是,如果您是喜歡git restore而不是git checkout ,那么等效的命令是:

git restore --merge -- <filepath>

git restore --conflict=diff3 -- <filepath

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM