guettli
guettli

Reputation: 27806

Show commits on detached head

If I do these steps:

  1. git checkout mytag # I am on detached head now.
  2. git commit
  3. git commit

Which git command can be used to see the changes between mytag and the current state?

This command should not use "mytag", since it is not available any more.

Upvotes: 0

Views: 695

Answers (2)

xlembouras
xlembouras

Reputation: 8295

try git merge-base

git log `git merge-base HEAD master`..HEAD

git merge-base will give you the common ancestor between two branches.
Then git log A..B will give you the commit history from A to B

instead of master you can use the branch where mytag started from.

Upvotes: 2

Nevik Rehnel
Nevik Rehnel

Reputation: 51935

You can use

git show

to view the changes introduced by the previous commit (the one where HEAD is currently pointing). You can also use git show <COMMIT> to view the changes introduced by any single commit you specify. (Details in the git show manpage.)

If you want to view the difference between two points, you can use

git diff <FROM> <TO>

where both <FROM> and <TO> refer to any commits (or references to commits, etc). (Details in the git diff manpage.)

In your specific case, when you want to view the difference between the current commit and two commits ago, you can use

git diff HEAD~2 HEAD

where HEAD~2 the 2nd-generation ancestor commit of HEAD (=where you currently are). This avoids using the refname of mytag, as you requested.

Details about the <ref>~<n> notation can be found in the gitrevisions manpage.

Upvotes: 1

Related Questions