Search code examples
gitgit-branchgit-commitgit-detached-headgit-dangling

How to git-commit from a branch to a detached HEAD?


My ref HEAD points the branch foo, that points to the commit 123abc; and I have some staged work.

How to git commit that work, moving the HEAD to the newly created commit, but without advancing the branch?

(hence: leaving foo point to 123abc)

Is it possible to do it with a single git command?


Solution

  • Simply detach, then commit:

    git checkout --detach
    git commit -m "Commit as usual"