5

I need to understand changes to a file between two releases represented by my current master and branch new_branch. Normally, I would run the following if path/name are the same in both branches.

git diff new_branch -- path/file

What do I do when path/file is different between the two branches?

I can fallback and create another cloned repository and checkout new_branch. Then do unix's sdiff. I was just wondering if the authors of git diff anticipated this scenario and built something in to handle it.

--Thank you, --Mike Jr.

Mike Jr
  • 187
  • 1
  • 7
  • If the answer does not work for you (like in my case), check https://stackoverflow.com/q/5730460/711006 for additional options. – Melebius Apr 20 '17 at 12:59

1 Answers1

5

Git has no real notion of moved/renamed/copied files, however it has heuristics to try and detect those cases and then display them in a nice way.

That said, you can instruct git-diff to use those heuristics to detect renames by passing it the -M flag. With that you can try

git diff -M new_branch -- new-path/file old-path/file

and see if it works in your specific case. Further, git diff -M --stat new_branch will give you an overview of the changes, and also show you what renames Git's heuristics picked up.

earl
  • 2,971
  • 24
  • 16