Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted

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.

share|improve this answer
Perfect. Worked like a champ. I wish the git-diff man page had included your example. – Mike Jr Aug 6 '10 at 14:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.