6

我最近在我的 git 合并策略上犯了一个错误,直到我已经继续在项目上工作并进行了更多提交时才注意到结果错误。为简洁起见,假设我有两个分支,hotfix并且new_feature. 我做了类似以下的事情:

git checkout new_feature
git commit -m "Commit to the feature branch"
git checkout hotfix
git pull origin new_feature # Uh oh, I pulled the wrong branch!
git commit -m "Commit to the hotfix"
git push origin hotfix # Uh Oh, pushed the bad merge!

在上述事件之后,其他开发人员也对 Hotfix 分支进行了提交。现在,我们有一个想要推出的修补程序,但不能推出,因为它包含未完成的功能工作。

我已经看到了很多关于这种情况的类似问题,但没有一个是 100% 匹配的(其中大多数涉及在糟糕的拉动之后直接撤消提交,而不是先推动。我更进一步,真的很无聊。

关于如何解决这个问题的任何分步指南?

谢谢!

编辑:许多其他答案都提到git reflog了,所以这是我的修改后的副本。我已经更改了哈希和分支名称以匹配我上面的示例。

aaaaaaa HEAD@{0}: checkout: moving from new_feature to hotfix
bbbbbbb HEAD@{1}: checkout: moving from hotfix to new_feature
aaaaaaa HEAD@{2}: commit: Added analytics tracking
ccccccc HEAD@{3}: commit (merge): Fixed a merge issue in compiled css # BAD MERGE?
ddddddd HEAD@{4}: checkout: moving from new_feature to hotfix
eeeeeee HEAD@{5}: commit: Finished updating the events for the header
ddddddd HEAD@{6}: checkout: moving from hotfix to new_feature
ddddddd HEAD@{7}: checkout: moving from new_feature to hotfix

在上面的 reflog 中,HEAD@{3}看起来是错误的合并。我在hotfix分支上,并拉入new_feature分支,这产生了合并冲突。我把它们修好,然后推。我该怎么做才能解决这个问题?

4

1 回答 1

3

找到提交哈希:git log --pretty=format:"%h %s" | grep "Commit to the hotfix"

还原“哦哦”的提交:git revert 15d2e1f -m 2

于 2013-07-30T16:10:20.227 回答