简体   繁体   中英

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM