通常,您可以执行以下操作:
$ echo "Stanley, you must beware of the Drive bee" > file-a
$ echo "What's a Drive bee?" > file-b
$ git init .
$ git add file-b
$ git commit file-b -m "We don't know, but whatever error you make with it could be fatal."
$ git reset --hard HEAD
$ ls
file-a file-b
我觉得我做了一件很糟糕的事情:
$ echo "What are you doing, you darn ?" > file-a
$ echo "Can't you see I'm trying to drive?" > file-
$ git init .
$ git add -A
$ git commit file- -m "Oh, my God! [It's] the Drive !"
$ git reset --hard HEAD
$ ls
file-
结果:所有暂存但未提交的文件已删除 0_o
git reset --hard HEAD\^
fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.
有什么办法可以恢复我刚刚删除的文件吗?换句话说,是否可以将 git 存储库恢复到git add -A
发出命令之前(或何时)的状态?