由于 reflog 中的 sha 相同,无法从 Git 恢复提交
Can't recover commit from Git due to same sha in 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 个命令只是我从一个分支切换到另一个分支,然后再返回尝试修复它。
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 的结帐之前在 repo 的 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}:
使用以下方法解决:
gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print }' )
来自:
How to recover a dropped stash in Git?
问题是 git reflog
将哈希缩写为 7 个字符,但是这两个提交中的前 7 个字符是相同的。
要使用 reflog 获取完整哈希,请使用此命令:
git reflog show --no-abbrev
然后,您可以使用完整的哈希值来签出您想要的提交。
我正在尝试恢复代码,因为我不小心切换到 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 个命令只是我从一个分支切换到另一个分支,然后再返回尝试修复它。
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 的结帐之前在 repo 的 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}:
使用以下方法解决:
gitk --all $( git fsck --no-reflog | awk '/dangling commit/ {print }' )
来自:
How to recover a dropped stash in Git?
问题是 git reflog
将哈希缩写为 7 个字符,但是这两个提交中的前 7 个字符是相同的。
要使用 reflog 获取完整哈希,请使用此命令:
git reflog show --no-abbrev
然后,您可以使用完整的哈希值来签出您想要的提交。