章鱼合并中分支的丢失提交历史记录

时间:2013-12-02 15:22:41

标签: git version-control merge

在一次(偶然)章鱼合并之后,我刚刚丢失了一个分支上的本地提交但却不明白为什么。
这是reflog:

8191469 HEAD@{0}: checkout: moving from develop to feature
832315f HEAD@{1}: checkout: moving from feature to develop
8191469 HEAD@{2}: merge develop: Merge made by the 'recursive' strategy.
e17facc HEAD@{3}: checkout: moving from develop to feature
832315f HEAD@{4}: pull: Fast-forward
fe8ddbb HEAD@{5}: checkout: moving from feature to develop
e17facc HEAD@{6}: commit: B.
4a3d1b7 HEAD@{7}: reset: moving to 4a3d1b79f15981e36fe20079acb7e376ff9a771d
b1635a3 HEAD@{8}: reset: moving to b1635a3a047a0eb0a0e71b7adc9348f6d3837359
9497ed9 HEAD@{9}: merge develop: Merge made by the 'recursive' strategy.
b1635a3 HEAD@{10}: commit (merge): Merge commit '4a3d1b79f15981e36fe20079acb7e376ff9a771d' into feature
ced6980 HEAD@{11}: merge e4403818b8296a2b0aa1e7bd46f59c809b0977b6: Merge made by the 'recursive' strategy.
da7a4bb HEAD@{12}: checkout: moving from develop to feature
fe8ddbb HEAD@{13}: pull origin develop: Fast-forward
2b639b0 HEAD@{14}: checkout: moving from feature to develop
da7a4bb HEAD@{15}: reset: moving to da7a4bb2fa71f327275ab82cd03e437f67ac4561
e806af4 HEAD@{16}: merge develop e4403818b8296a2b0aa1e7bd46f59c809b0977b6: Merge made by the 'octopus' strategy.
da7a4bb HEAD@{17}: commit: Older missing commits go on from here
                   .
                   .
                   .

对此的修正是here
我需要做的只是

git reflog 

中合并之前找到正确的提交
git reset --hard <sha1 of that commit>

为什么章鱼合并会删除分支的父节点?

1 个答案:

答案 0 :(得分:0)

在拉开发展之前你有没推动过?

da7a4bb HEAD @ {15}:重置:转到da7a4bb2fa71f327275ab82cd03e437f67ac4561

你确实在这里重置了,之后你做了

e806af4 HEAD @ {16}:merge develop e4403818b8296a2b0aa1e7bd46f59c809b0977b6:由“章鱼”策略合并。

开发密封顶部分支的合并......

如果你确实推了,那么在合并关闭开发之前重置提交可能会有所帮助(在特征上):

   git reset --hard <sha of commit before oct merge>
之后你应该能够通过git pull获得你失去的东西

如果你没有推送,那么你的数据可能会丢失,但试试这个:

在octo merge之前的那一点,使用此命令查找丢失的提交:

   git fsck --lost-found

此时,您可以再次使用reflog查看丢失的提交

如果git知道您丢失使用的提交

   git merge <sha of the lost commit git found for you>

恢复您宝贵的数据