我最初是在名为“feature
”的git分支上工作。然后,我提交了我的更改。
然后我注意到有一些新创建的文件不应该在我的提交中。所以我找到了最新提交哈希 1b33aa
(我使用git log
命令)。
之后,我做了:
git checkout 1b63aa
然后我做了更多更改(虽然我还在功能分支上......我的错误),并再次提交。
然后我运行git branch
,打印出来:
* (detached from 1b33aa)
feature
如何将我刚刚对feature
分支所做的更改合并回来?
答案 0 :(得分:7)
你现在在一个独立的分支上。您似乎想要将此feature
分支替换为此分支。一种安全的方法是将feature
重命名为其他内容,然后将当前分支转换为名为feature
的正确分支:
git branch -m feature feature-bak
git checkout -b feature
在您的第一步中,我认为您想要git reset
代替git checkout
:
git reset 1b63aa
另一方面,如果您不想替换feature
分支但将当前分支中的更改合并到feature
,则可以这样做:
git checkout -b temp
git checkout feature
git merge temp