简体   繁体   中英

In Git, how do I diff to the first commit of my branch?

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.

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.

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

您可以通过执行git log来获取分支点的SHA-1。

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).

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