为什么在这种情况下会丢失git commit?

时间:2019-04-20 03:43:13

标签: git git-rebase git-pull git-reflog reflog

我的同事进行了一系列粗心的拉/推操作。他最终遇到了本地承诺丢失的情况

我使用git reflog恢复了他的提交。但是我不知道为什么他的行动会导致这种情况。有人可以点灯吗?

请参见下面的git reflog输出和评论:

#######
# reflog is in reverse manner, most recent operation first
# test is like our "develop" branch, MTX-65 is the feature branch
# Both are remote-tracking
#######
39261b7 (HEAD -> MTX-65, origin/feature/MTX-65) HEAD@{0}: checkout: moving from test to MTX-65
7f66c72 (test) HEAD@{1}: checkout: moving from MTX-65 to test
39261b7 (HEAD -> MTX-65, origin/feature/MTX-65) HEAD@{2}: pull: Fast-forward
d51c1be HEAD@{3}: rebase finished: returning to refs/heads/MTX-65
d51c1be HEAD@{4}: rebase: Add Notification
c33d31f HEAD@{5}: pull --tags -r origin feature/MTX-65: checkout c33d31f4d0109396dea6d6bb78f47ba56097e4ac

#######
# This is the key commit that got lost
# It's not in `git log` out any more
#######
a6a7a7e HEAD@{6}: commit (merge): Warning message
3c8113c HEAD@{7}: commit (amend): Add Notification
7f551e4 HEAD@{8}: commit: Add Notification
96bcf99 HEAD@{9}: pull --tags -r origin feature/MTX-65: Fast-forward
b79bee0 HEAD@{10}: commit: personal & institution page
3cfb1aa HEAD@{11}: commit: Institution:
7f66c72 (test) HEAD@{12}: checkout: moving from test to MTX-65
7f66c72 (test) HEAD@{13}: merge MTX-65: Fast-forward
0733fd2 HEAD@{14}: checkout: moving from MTX-65 to test
7f66c72 (test) HEAD@{15}: commit (merge): Merge test
ebfaeea HEAD@{16}: checkout: moving from test to MTX-65
0733fd2 HEAD@{17}: pull: Fast-forward
1043c35 HEAD@{18}: checkout: moving from MTX-65 to test

#######
# This is a commit that still exists after the disaster
#######
ebfaeea HEAD@{19}: commit: institution 认证信息

1 个答案:

答案 0 :(得分:1)

让我们看看a6a7a7e HEAD@{6}: commit (merge): Warning message

commit (merge)表示合并遇到冲突。解决冲突后,您的同事将默认提交消息更改为Warning message。默认消息类似于Merge made by the 'recursive' strategy

然后您的同事运行git pull --tags -r origin feature/MTX-65。对于-r,在提取完成后,将使用git rebase代替git merge

正如manual所说,

  

默认情况下,rebase只会从待办事项中删除合并提交   列表,然后将重新提交的提交放入单个线性分支中。

git mergegit rebase上有更好的争论。 git rebase的优点之一是,我们可以使用它以方便的方式创建线性历史记录。按照设计,尽管git rebase提供了-r-p来保留合并提交,但默认情况下它们会被丢弃。

git rebase期间,预计会再次发生冲突。从理论上讲,如果您的同事以与以前的git merge相同的方式解决这些问题,这些更改就不会丢失。您可以尝试git log --reflog -S <keywords> -p来找出包括关键字在内的所有更改都在哪里提交。