由于reflog中的sha相同,无法从Git恢复提交

时间:2015-01-20 01:25:20

标签: git reflog

我试图恢复代码,因为我不小心切换到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的迟到提交还是丢失?

感谢。

P.S。其他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,这是在repo的zip文件中,然后我执行了所有那些检查,这些检查都充斥着reflog,所以它从@ {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}:

2 个答案:

答案 0 :(得分:5)

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

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

git reflog show --no-abbrev

然后,您可以使用完整哈希来检查您想要的提交。

答案 1 :(得分:1)

解决使用:

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

从:

How to recover a dropped stash in Git?