Zygro Zygro - 7 months ago 39
Git Question

How to overwrite a commit with detached HEAD commit?

I have a branch that looks like this

C (Detached HEAD)

I got it by this process:

git checkout branch
git checkout HEAD~
git commit -m "C"

and I want
to overwrite
(discard all changes in B)

Best would be without merging temp branch because I want the branch graph to look as simple as possible


Force delete the branch and create branch on the C commit. Do force push if branch is in any remote repository.

If you can repeate the commit (i.e. you have a diff saved somewhere), you can reset branch's HEAD to HEAD~ and the do the commit.