解决 git 中的“冲突(删除/修改)”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2314437/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Resolve "CONFLICT (delete/modify)" in git
提问by mokasin
In one branch in one branch A a file is changed and the change commited. Now in another branch B the very same file is edited and renamed.
在一个分支 A 中的一个分支中,文件被更改并提交了更改。现在在另一个分支 B 中,编辑并重命名了相同的文件。
When merging B into A git recognises the conflict properly (CONFLICT (delete/modify)) and both files are in the working directory.
将 B 合并到 A 时,git 正确识别冲突(CONFLICT (delete/modify))并且两个文件都在工作目录中。
If I know want to have both changes in one file, how do I do this best?
如果我知道要在一个文件中进行两项更改,我该如何做到最好?
There is git merge-filethat is - if I'm right - expecting both files and a common ancestor. But how to give latter? How can I say "use $path from $commit" or something like that?
有git merge-file是 - 如果我是对的 - 期待这两个文件和一个共同的祖先。但是如何给后者呢?我怎么能说“使用 $commit 中的 $path”或类似的话?
Example:
例子:
mkdir git-rename-repo
cd git-rename-repo
git init
echo "First line" > afile
git add .
git commit -m "First commit in master"
git checkout -b mybranch
echo "Second line in mybranch" >> afile
git mv afile bfile
git commit -a -m "change and rename in mybranch"
git checkout master
echo "Changed first line in master" > afile
git commit -a -m "changed afile"
git merge mybranch
I now want a file named 'bfile' with both changes:
我现在想要一个名为“bfile”的文件,其中包含两个更改:
Changed first line in master
Second line in mybranch
Changed first line in master
Second line in mybranch
Thanks
谢谢
回答by workdreamer
On my case, it was a deleted file not present on the repository
就我而言,这是存储库中不存在的已删除文件
CONFLICT (delete/modify): ERD.pdf deleted in HEAD and ...
I just need to do: git rm ERD.pdf
我只需要做: git rm ERD.pdf
Hope that helps.
希望有帮助。
回答by shah1988
I also had the scenario
我也有这样的场景
**CONFLICT (modify/delete):***FileName deleted in HEAD and modified in 6efb2a94ba0601aa1ec5050ab222a0359ee8379a. Version 6efb2a94ba0601aa1ec5050ab222a0359ee8379a of FileName left in tree.*
**冲突(修改/删除):***文件名在 HEAD 中删除并在 6efb2a94ba0601aa1ec5050ab222a0359ee8379a 中修改。FileName 的版本 6efb2a94ba0601aa1ec5050ab222a0359ee8379a 留在树中。*
I was also equally confused and reached this post.
But on typing git status
, all doubts are vanished. git status
, stated the following about the conflicted files:
我也同样困惑并到达了这篇文章。但在打字时git status
,所有的疑虑都烟消云散了。git status
,关于冲突文件的说明如下:
Unmerged paths:
(use "git add/rm ..." as appropriate to mark resolution)
未合并的路径:(根据需要
使用“git add/rm ...”来标记分辨率)
So I just did git rm FileName
, and after that the CONFLICT got resolved.
所以我就这样做了git rm FileName
,之后冲突得到了解决。
回答by mokasin
UPDATEOkay, git's recursive merge algorithm does this just fine by itself. I just used too small files to test it so the relative similiarity was beneath the trigger of the rename detection.
更新好的,git 的递归合并算法本身就可以做到这一点。我只是使用了太小的文件来测试它,因此相对相似性在重命名检测的触发之下。
If I change one line of a file with two small lines the relative change is very big.
如果我用两条小行更改文件的一行,则相对变化非常大。
Of course I could do something like
当然我可以做类似的事情
git show HEAD^:afile > afile_ancestor
kdiff3 -m afile_ancestor afile bfile
P.S.: Sorry for the broken formatting above. I didn't had switched on JavaScript, so I couldn't see a preview.
PS:很抱歉上面的格式损坏。我没有打开 JavaScript,所以我看不到预览。