Tom Hale Tom Hale - 2 months ago 9
Git Question

Move git HEAD without changing anything else

I want to move

HEAD
, and only do that.

This means I want to keep untouched:


  • Index (a.k.a. cache / staging area)

  • Working tree

  • Commit to which the current branch reference points



git reset --soft
does the first two, but not the last.

Is there a way to do this without creating a new branch?

Answer

You can achieve this by doing:

echo $(git rev-parse $commit) > $(git rev-parse --git-dir)/HEAD

But it is discouraged.