I'd like to know how you handle a situation like this in Git:
- create branch task001 from master
- master: modify foo.c and rename it to bar.c
- task001: modify foo.c and rename it to moo.c
- merge task001 to master
What Git tells me is:
CONFLICT (rename/rename): Rename "foo.c"->"bar.c" in branch "HEAD" rename "foo.c"->"moo.c" in "task001"
Automatic merge failed; fix conflicts and then commit the result.
How should I solve it? I mean, I still want to merge the two files once the name conflict is resolved.
Thanks.
I initially understood your question to mean something different from what you have clarified in the comments, but the original answer may be useful, so I'm leaving that as the first part, but adding an alternative below:
1. Just resolving the conflict, so you only have the diverged moo.c and bar.c
Here I'm assuming that the result you want is to have
bar.c
andmoo.c
, with their changes from each branch, in the merged version. I would deal with this by resolving the conflict in the index and committing. The situation you describe looks like this:If I then merge
task001
intomaster
, it produces the same error that you see:Then
git status
will show you a summary of problems:Now you just need to use
git add
andgit rm
to resolve the conflicts:(I used
--cached
for removingfoo.c
because it's no longer in the working copy, and--cached
means the command only looks at the index -- otherwise you get an error aboutfoo.c
not existing.)Then you just commit the results:
And you've resolved the conflicts and have
bar.c
andmoo.c
in the merged version.(I note in passing that
git merge -s resolve
works for me in the simple example situation describe here, but I hope this is more generally useful.)2. Merging bar.c and moo.c back into one file
It seems from your comments below that really what you would like is to merge these files back into one again, with the changes to the file in both branches merged. If you want git's merge strategies to help you with this, the files on each branch must have the same path before merging, so you'll need to rename at least one of them before merging. Let's suppose you want the merged file to be called
quux.c
, although you could just as well make itfoo.c
again, of course. Then you could do the following steps, which rename the file on each branch before merging:If the changes didn't conflict, then at this point that merge should Just Work. In the example I tried they did conflict, so I needed to edit the file,
git add
the file and commit the result:Simple way to fix this First abort the current merge
Now, decide which version of the file you want to use and use a merge strategy (with the flag -s)
You are on the branch master. If you want to keep the name you set in master then use this command
If you want to use the version from task