Question

I've made several commits to a local branch, but I'm not sure what the best way to diff what I currently have to my branch's starting state. I know I can do something like git diff HEAD HEAD~6 if there's been 6 commits to my branch, but I was hoping for something that was independent of the number of commits.

Edit: I failed to mention this: I was hoping I wouldn't have to dig through the log to get the hash of the commit I branched from. If I had 80 commits for example, this wouldn't be a fun task.

Also, presume that the original branch I branched from has already had several changes.

Was it helpful?

Solution

You'll want to use the triple dot syntax described in git help diff:

git diff otherbranch...

This is the same as:

git diff otherbranch...HEAD

which is the same as:

git diff $(git merge-base otherbranch HEAD) HEAD

The merge-base command prints the "best" (most recent) common ancestor, so the above command shows the difference from the most recent commit that HEAD has in common with otherbranch to HEAD.

Note you can use @{u} in place of otherbranch to see the changes you made since you diverged from the upstream branch. See git help revisions for details about the syntax.

OTHER TIPS

First, you need to find the commit you branched from. Once you have that, you can simply do a git diff <branch-point>..HEAD (as yasouser pointed out).

git diff <SHA-1 of the commit from which you branched>..HEAD

You can get the SHA-1 of your branch point by doing a git log.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top