In Git, how do I distinguish from the first commit of my branch?

I made several commits in the local branch, but I'm not sure the best way to distinguish what I have is from the state of my branch. I know that I can do something like git diff HEAD HEAD~6 if there were 6 commits in my branch, but I hoped that it did not depend on the number of commits.

Edit: I did not mention this: I was hoping that I would not have to break through the journal in order to get a hash from the commit that I was alienating from. For example, if I had 80 commits, that would not be a fun task.

In addition, suppose that the original branch I, branched, already had several changes.

+44
git git-diff
Jun 17 '11 at 19:58
source share
3 answers

You want to use the triple point syntax described in git help diff :

 git diff otherbranch... 

This is the same as:

 git diff otherbranch...HEAD 

which matches with:

 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 between the last commit that has HEAD from otherbranch to HEAD .

Note that instead of otherbranch you can use @{u} to see the changes you made after you diverged from the upstream branch. For more on syntax, see git help revisions .

+64
Jun 17 2018-11-18T00:
source share

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

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

0
Jun 17 '11 at 20:01
source share

First, you need to find the command you were branching with . After that, you can just do git diff <branch-point>..HEAD ..HEAD (as yasouser pointed out).

0
Jun 17 '11 at 20:05
source share



All Articles