Reputation: 798
I have two branches, master
and develop
. At the state of commit A
, a fileA
is in the directory /folderX/subfolderY/fileA
(and tracked). Now commit B
on master moves fileA
to the parent directory /folderX/fileA
(without modifying it); then comes commit C
which does some more stuff on other files. Commit D
in develop
modifies fileA
and moves it to the parent folder as well. The content of commit D
is therefore
/folderX/subfolderY/fileA
/folderX/fileA
.Note that fileA
is tracked in both branches.
--A--B--C master
\
D develop
I would like to keep the modified version of fileA
of develop in the end.
Now if I merge develop
into master
, git tells me there is a merge conflict because fileA
has been created in master but deleted in develop
. More precisely, it states:
CONFLICT (rename/delete): /folderX/subfolderY/fileA deleted in D develop and renamed to /folderX/fileA in HEAD. Version HEAD of /folderX/fileA left in tree.
If I try to resolve with git mergetool
, git gives me the usual options:
Deleted merge conflict for '/folderX/fileA':
{local}: created file
{remote}: deleted
Use (c)reated or (d)eleted file, or (a)bort?
However, if I choose (c)created
, the unmodified version of fileA
is retained. If I choose (d)eleted
, I end up without fileA
.
I expected git to compare /folderX/fileA
from master to the modified /folderX/fileA
from develop and to create a merge commit out of the resulting difference. What am I missing
Upvotes: 1
Views: 2787
Reputation: 2498
You can do git merge by ignoring rename.
git merge -s recursive -Xno-renames develop
This will result in git reporting the file modified by both the branches. Now you can use git mergetool
or run, git checkout --theirs folderX/fileA
to get develop version.
Upvotes: 3
Reputation: 30277
Keep the file as it is in D, because B only renamed it (to the same thing as D):
git checkout D -- folderX/fileA
And remove other conflicting instances of the file that are in the index.
Upvotes: 1