KcFnMi
KcFnMi

Reputation: 6161

Move commit made in detached HEAD back to branch, but not on top

  1. I was on current branch and did commit good.
  2. Then I commited irrelevant.
  3. I went back, checked out good (detached HEAD now).
  4. I did commit one, in detached HEAD state.

I would like to have some help to put one just after good, in current branch.

It doesn't matter if I lost irrelevant.

Upvotes: 0

Views: 319

Answers (1)

jthill
jthill

Reputation: 60255

  1. I went back, checked out good (detached HEAD now).
  2. I did commit one, in detached HEAD state.

I would like to have some help to put one just after good.

one is after good. git commit updates HEAD, every time, no matter what. When you check out a branch tip, git sets the HEAD reference as an alias for that branch tip reference, it "attaches" it to that branch tip reference. A detached HEAD is just a reference directly to a particular commit, so when git commit updates it, HEAD now refers to the new one. But git commit always adds the old HEAD commit as the parent of the new one.

So just

git checkout -B current one               # if you don't still have `one` checked out

or just

git checkout -B current                   # if you do

Upvotes: 2

Related Questions