Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
341 views
in Technique[技术] by (71.8m points)

Resolve "CONFLICT (delete/modify)" in git

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.

When merging B into A git recognises the conflict properly (CONFLICT (delete/modify)) and both files are in the working directory.

If I know want to have both changes in one file, how do I do this best?

There is git merge-file that 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?

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:

Changed first line in master Second line in mybranch

Thanks

question from:https://stackoverflow.com/questions/2314437/resolve-conflict-delete-modify-in-git

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I also had the scenario

**CONFLICT (modify/delete):***FileName deleted in HEAD and modified in 6efb2a94ba0601aa1ec5050ab222a0359ee8379a. Version 6efb2a94ba0601aa1ec5050ab222a0359ee8379a of FileName left in tree.*

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:

Unmerged paths:
(use "git add/rm ..." as appropriate to mark resolution)

So I just did git rm FileName, and after that the CONFLICT got resolved.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...