简体   繁体   English

GIT 分支上的分离头问题

[英]GIT Detached head issue on a branch

I created a branch for my change and did a lots of commit over there.我为我的更改创建了一个分支,并在那里做了很多提交。 But then I wanted to rollback my latest commit.但后来我想回滚我最近的提交。 sO i did following 1. I checkout the previous commit with git checkout on my branch.所以我做了以下 1. 我在我的分支上使用 git checkout 签出之前的提交。 2. Then I did my changes to local directory and committed the changes. 2. 然后我对本地目录进行了更改并提交了更改。

Now I am not able to push it to the branch head.现在我无法将它推到分支头。 It is showing as detached head and can't see this commit in GIT UI.它显示为分离的头,在 GIT UI 中看不到此提交。

Please note I want to push the changes to the head of my branch and not to the master.请注意,我想将更改推送到我的分支头部而不是主分支。 Any help?有什么帮助吗?

# create a branch where you're currently pointing at
git branch temp

git checkout your_branch
git merge temp

and the commit you made out of your branch will be brought in, it should be a fast-forward (so without an unnecessary merge commit).并且您从分支中所做的提交将被引入,它应该是快进的(因此没有不必要的合并提交)。

If I understood correctly, you checked out your previous commit without resetting your branch to it, therefore detaching HEAD .如果我理解正确,您检查了您之前的提交而没有将您的分支重置为它,因此分离了HEAD To bring back the branch to your current HEAD (and drop the commit it was pointing to), just use:要将分支恢复到当前的HEAD (并删除它指向的提交),只需使用:

git checkout -B your_branch # Reset your_branch to HEAD and attach to it

If you had already pushed the dropped commit, you will need to --force the next push.如果您已经推送了已删除的提交,则需要--force下一次推送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM