1

I am attempting to merge master into a dev branch with a lot of changes and ran into some merge conflicts.

How can I get a diff of what changed in the file since the last shared commit in my dev branch using the git console commands?

So lets say my branches have the following last 5 commits:

master:
  abb
  abc
  abd
  abe
  abf

dev:
  abb
  cda
  abc
  abd
  cdb (merge master to dev at abd)
  cdc

And I would now like the equivalent of:

git diff abd..abf filename.ext

But, because I am in the middle of a merge with conflicts, i'm not sure how to find those two commit hashes without looking through the log's of both master and dev.

Realistic
  • 1,038
  • 1
  • 10
  • 20
  • Maybe you can use a tool like SourceTree on Windows or SmartGit on Linux could help you to find the commit hashes. Having a visual representation of the branches will maybe clarify your situation and they can let you diff through different commits pretty easily. – pandaman1234 Jul 12 '16 at 18:25
  • @lordjohncena Thanks for the info. I have updated the question to explicitly state I would like a console based solution. – Realistic Jul 12 '16 at 18:29

2 Answers2

2

Writing up this question helped me realize how to search for the answer which is this:

git diff $(git merge-base master dev) master filename.ext

Explanation:

git merge-base master dev

Will find the most recent common ancestor between the two branches

git diff <base commit> master

Will show a diff between the commit specified and the newest commit within the master branch.

Note:

If you want to be sure you are looking at the latest, use origin/master instead to diff between the remote.

Community
  • 1
  • 1
Realistic
  • 1,038
  • 1
  • 10
  • 20
0

Git diff has a special form of the '...' operator, so the following will work also.

git diff dev...master filename.ext

see git help diff

Gregg
  • 2,444
  • 1
  • 12
  • 21