what are some situations where you've needed to think about what HEAD is in git?
so far I have:
- git checkout HEAD^^
- git rebase -i HEAD^^^^
- git diff HEAD
- git push origin HEAD:targetbranch
- HEAD~1, HEAD~2, etc
- git show HEAD^
- git reset --hard HEAD^
and in git's output:
- "detached HEAD state"
- merge conflicts (β<<<<<<< HEADβ)
- git reflog output ("(HEAD -> main)β)
- git reflog output ("HEAD@{5}β)
what else?
@b0rk "git rebase HEAD^", when splitting commits in a work branch
@monsieuricon @b0rk dude, you can just say "git show" (also, "git diff", "git reset --hard"...)
:(
git reset --hard HEAD
git diff HEAD
git push origin HEAD
git diff
vs. git diff HEAD
in my next git session.@vv221 (the difference is that `git diff` doesn't include staged changes and `git diff HEAD` does)
@b0rk I regularly do git rebase βautosquash with some variant of HEAD~N
@b0rk Related news: The latest git release supports autosquash in non-interactive rebase mode!
@b0rk Also, I often do git log -p comparing FETCH_HEAD and ORIG_HEAD.
Usually in some form of workspace update automation script, to inform me of incoming and outgoing changes.
@calisti oh that's awesome, I didn't realize that non-interactive rebase **didn't** support autosquash but it's cool that it does now!
@joshsusser @b0rk the difference between ^ and ~ has never been clear to me
@snim2 @joshsusser i just learned what the difference is recently! wrote about it a bit here https://jvns.ca/blog/2023/11/01/confusing-git-terminology/#head-head-head-head-head-2-head-2
it's interesting that HEAD means slightly different things depending on the situation, for example:
1. βgit show HEAD" means "show me the latest commit on the current branch"
2. β5aad10 (HEAD -> main)" in git log's output means βyour current branch is `main`, and 5aad10 is the latest commit on `main`β
3. β<<<<<<<<< HEAD" in a merge conflict honestly means nothing to me, I ignore the HEAD because how it relates to where you started is inconsistent between merge and rebase. it's too confusing.
@b0rk rebase getting HEAD backwards and just noting it as a little aside in the documentation is among git's worst things.