0

我不确定我做了什么,因为我不太了解 git,只是开始输入命令。我的意图是删除自上次提交以来所做的更改,但看起来我已经删除了存储库中自第一次提交以来的所有更改。当我运行 git log 时,只显示 2/23 的提交。是否有命令可以恢复最新版本?

@Adrian 指出 git reflog:这是我的输出。签出 HEAD@{1} 的命令是什么?

26ceb46 HEAD@{0}: reset: moving to 26ceb4673a42710adb16840cc2f96e2073869eb5
e9c0494 HEAD@{1}: commit: After root fiasco, about to change illustration, novel, and edition models
e6ca6e6 HEAD@{2}: commit: Before adding edition as a table
17b2d98 HEAD@{3}: commit: Added search grid view, pagination on search grid view and index view.
d582f81 HEAD@{4}: commit: Before fixing tag display page
117cf37 HEAD@{5}: commit: Commit before adding tagging_id to illustration table
a543a4b HEAD@{6}: commit: Search bar and search results page working
d372d6e HEAD@{7}: commit: Fixed formatting, added search bar
0188759 HEAD@{8}: commit: Style changes, implemented basic grid views, Removed extra models/controlle
003cc92 HEAD@{9}: commit: Swapped to mysql
8cfd94e HEAD@{10}: checkout: moving from master to mysql-transition
8cfd94e HEAD@{11}: commit: Before Novel
2cc012b HEAD@{12}: commit: Archive Scaffold
26ceb46 HEAD@{13}: commit (initial): Archive Scaffold
4

3 回答 3

1

Now that you've identified the commit you want to restore, you can issue the command

git checkout e9c0494
于 2013-04-13T19:22:47.090 回答
1

键入git reflog。您将列出所有更改的历史记录。您可以在更改之前安全地签出以提交。

于 2013-04-13T19:11:26.243 回答
0

This should list all the unreachable commits still present in your reflog.

git fsck --unreachable --no-reflogs 2>/dev/null | grep 'unreachable commit' | awk '{print $3;}

Then you could run git show SHA1 to display the commit message and the diff.

Note that unreachable git commits are kept in reflogs for a period of only 30 days.

Example:

$ git fsck --unreachable --no-reflogs 2>/dev/null | grep 'unreachable commit' | awk '{print $3;}
bb308ef25fd7c3e0e5643bfec6a64c990724f25c
f0067516d9ce241a7fad1d03f4bd418172d1c7c4
f226f1200efdbe3687760e717d6670715e288439

$ git show bb308ef25fd7c3e0e5643bfec6a64c990724f25c
commit bb308ef25fd7c3e0e5643bfec6a64c990724f25c
Author: Ash <tuxdude@Suse1520>
Date:   Sat Mar 23 13:36:36 2013 -0700

    Removed Something.

diff --git a/file1 b/file1
index b9330fb..e69de29 100644
--- a/file1
+++ b/file1
@@ -1 +0,0 @@
-SOMETHING

If you want to see how a work-tree looks like, you could also directly checkout that commit using git checkout SHA1

于 2013-04-13T19:22:12.870 回答