[英]merge changes on detached branch after git checkout <commit hash>
I was originally working on git branch named " feature
". 我最初在git分支上工作,命名为“
feature
”。 Then ,I commited my changes . 然后,我提交了我的更改。
Then I noticed there are some new created files shouldn't be in my commit. 然后我注意到有一些新创建的文件不应该在我的提交中。 So I found the lastest commit hash
1b33aa
(I use git log
command). 所以我找到了最新的提交哈希
1b33aa
(我使用git log
命令)。
After that, I did: 在那之后,我做了:
git checkout 1b63aa
Then I made more changes (I though I was still on feature branch...my mistake), and commited again. 然后我做了更多的更改(我虽然我还在功能分支......我的错误),并再次提交。
Then I run git branch
,it prints out : 然后我运行
git branch
,打印出来:
* (detached from 1b33aa)
feature
How can I merge back those changes I just made to feature
branch now? 如何将我刚刚对
feature
分支进行的更改合并回来?
You are on a detached branch now. 你现在在一个独立的分支。 It seems you want to replace your
feature
branch with this one. 您似乎想要用这个替换您的
feature
分支。 A safe way to do that is to rename feature
to something else and then turn the current branch into a proper branch named feature
: 一种安全的方法是将
feature
重命名为其他feature
,然后将当前分支转换为适当的分支命名feature
:
git branch -m feature feature-bak
git checkout -b feature
In your first step, I think you wanted to do a git reset
instead of a git checkout
: 在你的第一步,我想你想做一个
git reset
而不是git checkout
:
git reset 1b63aa
On the other hand, if you don't want to replace the feature
branch but merge the changes in the current branch to feature
, you can do like this: 另一方面,如果您不想替换
feature
分支但将当前分支中的更改合并到feature
,则可以这样执行:
git checkout -b temp
git checkout feature
git merge temp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.