开发者

How do I get my 'Detached HEAD' commits back into master [duplicate]

开发者 https://www.devze.com 2023-02-07 19:24 出处:网络
This question already has answers here: How can I reconcile detached HEAD with master/origin? (28 answers)
This question already has answers here: How can I reconcile detached HEAD with master/origin? (28 answers) Closed 7 years ago.

Looks like a few days ago I created a开发者_如何学C branch called detached HEAD and have been committing to it. My normal process is to commit to master and then push that to origin. But I can't push detached HEAD.

My next stop screwed me. I selected git checkout master - and my detached HEAD branch disappeared. Going back to my project all of my changes in the past few days have been wiped.

Is there anyway I can get those changes back?


If checkout master was the last thing you did, then the reflog entry HEAD@{1} will contain your commits (otherwise use git reflog or git log -p to find them). Use git merge HEAD@{1} to fast forward them into master.

As noted in the comments, Git Ready has a great article on this.

git reflog and git reflog --all will give you the commit hashes of the mis-placed commits.

How do I get my 'Detached HEAD' commits back into master [duplicate]

Source: http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html


If your detached HEAD is a fast forward of master and you just want the commits upstream, you can

git push origin HEAD:master

to push directly, or

git checkout master && git merge [ref of HEAD]

will merge it back into your local master.

0

精彩评论

暂无评论...
验证码 换一张
取 消