← Back to context

Comment by lalaithion

2 days ago

None of these seem to preclude a command to make an arbitrary branch point to an arbitrary commit without changing anything else.

This works if the branch exists or creates it if it doesn't exist, but not if it's checked out.

    git branch -f branch_name commit

if it's checked out:

    git reset --hard commit

  • > but not if it's checked out

    ...and for a good reason that should be apparent to anyone who understands git's model (HEAD points to a ref in this case, so if you suddenly change what that ref points to without updating the working tree you create an inconsistency).

    You can do that manually of course (with `git update-ref` or even a text editor), but then you get to clean up the mess yourself.