无法从 Git 恢复提交,因为 reflog 中的 sha 相同



我正在尝试恢复代码,因为我不小心切换到 eclipse 中的一个分支并丢失了所有数据,不知何故(我仍然不知道我做了什么)。当我在命令行中打开我的 git reflog 时,我看到:

6dc60f6 HEAD@{14}: commit: fixed class mismatch for integers
638fbb1 HEAD@{15}: commit: fixed first NPE bug
22fc2b9 HEAD@{16}: commit: v 6.0.5
0acef4f HEAD@{17}: commit: clean up
8a441cb HEAD@{18}: commit: cleaned up db code
9ac384d HEAD@{19}: commit: ver 6.0.4
ce1f1c2 HEAD@{20}: commit: addded drivers
9b5a4dd HEAD@{21}: checkout: moving from master to 9b5a4dde0f97303579ec0cf15413ecce83a636dc
6dc60f6 HEAD@{22}: commit: change Db
9b5a4dd HEAD@{23}: commit: // for public schema: "" or "public" 
f668dd1 HEAD@{24}: commit: changed schema
a0e5b2a HEAD@{25}: commit: changed frames

我正在尝试结帐6dc60f6 HEAD@{14}: commit: fixed class mismatch for integers但我所有尝试检查它都转到6dc60f6 HEAD@{22}: commit: change Db这是一个旧版本。这是来自git reflog命令,而不是 git log因此签出@{14}也不起作用。

有没有办法签出6dc60f6的后期提交,还是丢失了?

谢谢。

附言其他 14 个命令只是我从一个 brach 切换到另一个 brach,然后再次尝试修复它。

638fbb1 HEAD@{0}: checkout: moving from 6dc60f6 to master
638fbb1 HEAD@{1}: checkout: moving from ce1f1c247f94298c9e1fd67f0e1199a82df2ff1c to 6dc60f6
ce1f1c2 HEAD@{2}: checkout: moving from 6dc60f6 to ce1f1c2
638fbb1 HEAD@{3}: checkout: moving from master to 6dc60f6
638fbb1 HEAD@{4}:
6dc60f6 HEAD@{5}: checkout: moving from 6dc60f6f81a9f97d6d1244a288bec027fd7604b6 to master
6dc60f6 HEAD@{6}: 
638fbb1 HEAD@{7}: checkout: moving from ce1f1c247f94298c9e1fd67f0e1199a82df2ff1c to 638fbb1
ce1f1c2 HEAD@{8}: checkout: moving from 9b5a4dde0f97303579ec0cf15413ecce83a636dc to ce1f1c2
9b5a4dd HEAD@{9}: checkout: moving from 638fbb18fbe0dfd7bca8477d7b9ddde44443ed4a to 9b5a4dd
638fbb1 HEAD@{10}: checkout: moving from 6dc60f6f81a9f97d6d1244a288bec027fd7604b6 to 638fbb1
6dc60f6 HEAD@{11}: checkout: moving from 638fbb18fbe0dfd7bca8477d7b9ddde44443ed4a to @{6}
638fbb1 HEAD@{12}: checkout: moving from master to 638fbb1
6dc60f6 HEAD@{13}: checkout: moving from 078b90ff9eb70560ecf5e9a25b1f7aaa7db9a81a to master
078b90f HEAD@{14}: checkout: moving from master to @{5}
6dc60f6 HEAD@{15}: checkout: moving from latest_branch to master
6dc60f6 HEAD@{16}: checkout: moving from new_branch to latest_branch
6dc60f6 HEAD@{17}: checkout: moving from master to new_branch

编辑 2:

运行git reflog show --no-abbrev,这是在我完成所有淹没 reflog 的结帐之前在存储库的 zip 文件上,因此它从 @{0} 开始,请注意具有相同哈希但不同提交消息的 2(HEAD、master):

6dc60f6f81a9f97d6d1244a288bec027fd7604b6 (HEAD, master) HEAD@{0}: commit: fixed class mismatch for integers
638fbb18fbe0dfd7bca8477d7b9ddde44443ed4a HEAD@{1}: commit: fixed first NPE bug
22fc2b9e22e9259858f5d8df6b44fdd17e7ef475 HEAD@{2}: commit: v 6.0.5
0acef4fef3df6df7b6f77ef3d373f3071aafdc4a HEAD@{3}: commit: clean up
8a441cbfc8b68b25fe6cc2e96ed5cad797ba139c HEAD@{4}: commit: clean up db code
9ac384dfec998e3c7ea0641ba04025d5c0aa4abb HEAD@{5}: commit: ver 6.0.4
ce1f1c247f94298c9e1fd67f0e1199a82df2ff1c HEAD@{6}: commit: added drivers
9b5a4dde0f97303579ec0cf15413ecce83a636dc HEAD@{7}: checkout: moving from master to 9b5a4dde0f97303579ec0cf15413ecce83a636dc
6dc60f6f81a9f97d6d1244a288bec027fd7604b6 (HEAD, master) HEAD@{8}: commit: change Db
9b5a4dde0f97303579ec0cf15413ecce83a636dc HEAD@{9}: commit: // for public schema: "" or "public"
f668dd11646727dae7b8511796a88c59d439c2bf HEAD@{10}: commit: changed schema
a0e5b2a2c349ae0665f80fa1b7027836c8bbc6aa HEAD@{11}: commit: changed frames
2e934ffe0546413e7a7e81318f9e7aefc458e8d2 (origin/master) HEAD@{12}: commit: Change classes: BusinessRules - fix compliler error DBMetaInfopanel - fix dialog: MSDOC-ISSUE-007, MSDOC-ISSUE-010 ReportTable - fix DateTime and Number format Config.txt - add global DateTime and Number format add jar Profiler 6.0.4
078b90ff9eb70560ecf5e9a25b1f7aaa7db9a81a HEAD@{13}: commit: apply 6.0.3.2 fix and changed global parameters in Config.txt commented all DBs in Config.txt
9fb275d45da8e2df3044448b3275aa24a77ddd85 HEAD@{14}: commit: change framework version to 6.0.4
9835cdf1ba1d38bf3343e43623bd31f2aa0562b6 HEAD@{15}: commit: add Datetime and number format
839fa8b27a1c7a05fa19d75b5c62a8f35a865b9d HEAD@{16}: commit: add new profiler-6.0.3.4 remove profiler-6.0.3.1 change pom.xml
68acc9cfd9e0bc65159e35e832afa59d4d014717 HEAD@{17}: commit: add 6.0.3.1
46b0d9c2c8d4ac81f951ae41e2f405c864f430b0 HEAD@{18}:

问题是git reflog将哈希缩写为 7 个字符,但这两个提交中的前 7 个字符是相同的。

要使用 reflog 获取完整哈希,请使用以下命令:

git reflog show --no-abbrev

然后,您可以使用完整哈希签出所需的提交。

使用以下命令解决:

gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )

从:

如何恢复 Git 中丢弃的存储?

相关内容

  • 没有找到相关文章

最新更新