Jiaxiang Liang Jiaxiang Liang - 6 months ago 47
Git Question

git reset failed to change the HEAD

What I have in the work tree

* 63a7b9f 2017-08-21 | temp commit (HEAD) [Jiaxiang Liang]
* ad8d3f2 2017-08-19 | adding gitignore [Jiaxiang Liang]
* a562db1 2016-03-31 | revert to correct bugfix [Y. Yan]
* 3b24fd4 2016-03-31 | old src old test [Y. Yan]
* f9b4935 2016-03-31 | old src new test [Y. Yan]
* 6bf6585 2016-03-31 | new src new test [Y. Yan]
* 71209a6 2016-03-31 | new src old test [Y. Yan]
* 3114478 2016-03-15 | bugfix: anti-flow for push pop and peek [Y. Yan]

What I want to do is to delete commit
and move the head to
. I don't care about anything in
. So I did

git reset --hard ad8d3f2
HEAD is now at ad8d3f2 adding gitignore

It seems to delete the commit, but I have this thing which is bugging me:

git status

HEAD detached from 63a7b9f
nothing to commit, working directory clean

So I am wonder why the HEAD is not moving. I do want the HEAD to point to
. I want something like after
git reset

git status
HEAD detached at ad8d3f2

Solution: so the answers suggested to use branch gave me some ideas to solve my problem. Notice that I forgot to mention that all of the commits are in status
HEAD detached at <commit>

git branch temp
git checkout temp
git checkout ad8d3f2 //may not be necessary
git branch -d temp

After this, I got my desired status.

Answer Source

The output HEAD detached from <commit> is based on the reflog for HEAD, not its current value. This is arguably a bug, but it doesn't mean you aren't on a different detached HEAD now than you were.

Specifically, once HEAD is detached, there is no branch to reset. Using git reset --hard <commit> simply sets up the index and work-tree while setting HEAD to that commit, as if you had done another git checkout -f <commit>. HEAD remains detached; only git checkout <name>, for some valid branch name <name>, will re-attach your HEAD.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download