Realistic
Realistic

Reputation: 1068

How can I get a diff of a file since the last time I merged?

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.

Upvotes: 1

Views: 71

Answers (2)

Gregg
Gregg

Reputation: 2624

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

Upvotes: 0

Realistic
Realistic

Reputation: 1068

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.

Upvotes: 2

Related Questions