在做git commit时我意外删除了所有内容

时间:2017-03-24 04:50:55

标签: git

我不知道发生了什么。我试图承诺,当我去推动掌握它说我是最新的,没有任何事情发生。

(py35) $ git status
On branch jt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)

modified:   rt/models.py
modified:   rt/test_models.py

Untracked files:
(use "git add <file>..." to include in what will be committed)

../.DS_Store
.DS_Store
rt/.DS_Store
rt/migrations/.DS_Store
rt/migrations/0005_auto_20170323_2255.py
rt/migrations/0006_department_org.py
rt/migrations/0007_auto_20170323_2309.py
rt/migrations/0008_auto_20170323_2311.py
rt/migrations/0009_auto_20170323_2313.py
rt/migrations/0010_auto_20170323_2315.py

no changes added to commit (use "git add" and/or "git commit -a")
(py35) $ git add .
(py35) $ git commit -m "edits to models, fixed up team and dept, tested with presentation and working paper"
[jt cea85b9] edits to models, fixed up team and dept, tested with presentation and working paper
 Committer: Jonathan <xxxxxxxxxx>
 Your name and email address were configured automatically based
 on your username and hostname. Please check that they are accurate.
 You can suppress this message by setting them explicitly. Run the
 following command and follow the instructions in your editor to edit
 your configuration file:

 git config --global --edit

 After doing this, you may fix the identity used for this commit with:

 git commit --amend --reset-author

 11 files changed, 398 insertions(+), 79 deletions(-)
 create mode 100644 mysite/.DS_Store
 create mode 100644 mysite/rt/.DS_Store
 create mode 100644 mysite/rt/migrations/.DS_Store
 create mode 100644 mysite/rt/migrations/0005_auto_20170323_2255.py
 create mode 100644 mysite/rt/migrations/0006_department_org.py
 create mode 100644 mysite/rt/migrations/0007_auto_20170323_2309.py
 create mode 100644 mysite/rt/migrations/0008_auto_20170323_2311.py
 create mode 100644 mysite/rt/migrations/0009_auto_20170323_2313.py
 create mode 100644 mysite/rt/migrations/0010_auto_20170323_2315.py
 (py35) $ git push origin master
 Everything up-to-date

在此之后我做了一些蠢事并且跑了

git log -1
git reset --hard dd882d0aa067c60dd92610d1fa6b32548e70f596

然后将文件更改回上次提交时的状态。甚至改变我在IDE中打开的内容。

如何才能获得我今天所做的所有更改?我知道他们在那里,因为当我查看/.git/lost-found/other时,他们就在那里。我不知道如何使用它们。

1 个答案:

答案 0 :(得分:2)

以下命令可以通过将HEAD指向先前的提交来恢复:

git reset --hard HEAD@{1}

请在输入此之前制作整个项目目录的备份副本,以防止对解决方案造成任何混淆。