Show commits on detached head
If I do these steps:
- git checkout mytag # I am on detached head now.
- git commit
- 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.
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.
You can use
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.