2

I am trying to pull master-dev into my branch. My branch has moved a file (git sees this as the file being deleted and a new file made), but the same file has been modified in master-dev.

I have moved it from 'a/myfile.py' to 'b/myfile.py'.

I want to get the changes from master-dev, but have the file in the new location.

There may have also been changes made after moving the file in my branch, if this is the case, I would like to see both sets of changes and then pick the best change.

I have checked out my branch, and then run git pull origin master-dev. It reported merge conflicts, so I ran git mergetool, which I have configured to use MELD.

I have resolved a few other conflicts, but it has now reached the file in question, and git mergetool has prompted:

Deleted merge conflict for 'a/myfile.py':
  {local}: deleted
  {remote}: modified file
Use (m)odified or (d)eleted file, or (a)bort?

But unlike the other conflicts it has not opened meld, so I cannot see what the changes are in {remote} i.e master-dev. I also do not know if the file was changes as well as moved.

Can I tell git to delete this file, but then compare the changes between the {remote} and the new file? Or is there another solution to this problem?

Is there a manual solution to this? What steps should I take to ensure that I do this cleanly without loosing any potential good changes from either branch?

Thanks.

Blue7
  • 1,750
  • 4
  • 31
  • 55
  • 2
    Does [this](https://stackoverflow.com/questions/3491270/git-merge-apply-changes-to-code-that-moved-to-a-different-file) solve your problem? – ParSal Feb 18 '22 at 16:03

1 Answers1

1

You can use the standard patch utility to directly apply the diff to the renamed file :

# 3 dots :
git diff my_branch...master-dev -- a/myfile.py |\
    patch b/myfile.py

If that works, "solving" the conflict consists in deleting the old file ((d) option)


About the 3 dots notation in git diff, quoting git help diff :

git diff [<options>] <commit>...<commit> [--] [<path>…​]

This form is to view the changes on the branch containing and up to the second <commit>, starting at a common ancestor of both <commit>. git diff A...B is equivalent to git diff $(git merge-base A B) B.

LeGEC
  • 46,477
  • 5
  • 57
  • 104