Conversation
Edited 1 year ago

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?

7
0
0

@b0rk "git rebase HEAD^", when splitting commits in a work branch

1
0
0

Ε‘el pro krev πŸ‡ΊπŸ‡¦

Edited 1 year ago

@ebassi @b0rk yes and git rebase -i HEAD^^^^^^^^^^^^ if you've done too many git commit -amlalalala and now you need to squash them

0
0
1
@b0rk 'git show HEAD' to see what was the last thing you worked on.
1
0
2
@b0rk also 'git verify-commit HEAD' to make sure the sources are trusted (only if you use git commit signing).
0
0
1

@monsieuricon @b0rk dude, you can just say "git show" (also, "git diff", "git reset --hard"...)

:(

1
0
1
@lkundrak @b0rk it's one of those rules like with Spanish where you can start your sentence with "yo" or skip it, doesn't matter -- it's just something you do or don't. :) I like to be explicit, plus it's not like HEAD takes that long to type.
0
0
2

@b0rk Detached Head State is the best band name

1
0
1
ominous-sounding variant
Show content

@dbarbrow @b0rk Detached Head of State also sounds ominous.

0
0
0
I think for the three first examples the "HEAD" target is implicit (it can be omitted from the command, with no difference in behaviour), so one can have been using these for a long time without even noticing that the manipulations are related to HEAD.



EDIT: At the time of this message, the first three examples were:
- git reset --hard HEAD
- git diff HEAD
- git push origin HEAD
1
0
0

@vv221 git diff HEAD is different actually!

1
0
0
Argl, this is tricky!

Thanks for the precision, I will take the time to experiment a bit with git diff vs. git diff HEAD in my next git session.
1
0
0

@vv221 (the difference is that `git diff` doesn't include staged changes and `git diff HEAD` does)

0
0
0

Calisti πŸ³οΈβ€πŸŒˆπŸ¦‡

Edited 1 year ago

@b0rk I regularly do git rebase β€”autosquash with some variant of HEAD~N

2
0
0

Calisti πŸ³οΈβ€πŸŒˆπŸ¦‡

Edited 1 year ago

@b0rk Related news: The latest git release supports autosquash in non-interactive rebase mode!

1
0
0

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

0
0
0

@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!

0
0
0

@joshsusser @b0rk the difference between ^ and ~ has never been clear to me

1
0
0

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.

1
0
0

@b0rk rebase getting HEAD backwards and just noting it as a little aside in the documentation is among git's worst things.

1
0
0

@richlowe yeah on some level I understand why but it's SO confusing

0
0
0