2017-02-23 49 views
1

我提交了一些文件后,本地文件被更改。现在我想恢复本地目录与上次提交完全相同。在下图中,本地未提交的更改已损坏,因此我想取出主基本操作员....我已尝试git reset [the first commit hash code from git log],但没有任何更改。git如何恢复上次提交文件

enter image description here

回答

1

git reset <commit>改变您的HEAD点,但不会将您的文件恢复到他们是如何在这个承诺。如果你想将文件还原到它的外观在提交时,需要git reset --hard <commit>

关于三种复位模式:

 --soft 
      Does not touch the index file or the working tree at all (but 
      resets the head to <commit>, just like all modes do). This 
      leaves all your changed files "Changes to be committed", as git 
      status would put it. 

     --mixed 
      Resets the index but not the working tree (i.e., the changed 
      files are preserved but not marked for commit) and reports what 
      has not been updated. This is the default action. 

      If -N is specified, removed paths are marked as intent-to-add 
      (see git-add(1)). 

     --hard 
      Resets the index and working tree. Any changes to tracked files 
      in the working tree since <commit> are discarded. 
+0

后的git的复位 - 硬[提交哈希码]我注意到自上次提交后添加的文件仍然存在。 – Tiina

+0

@Tina:reset --hard将不会删除自上次提交以来添加的任何新文件,因为您尚未(尚未)告知git“观察”这些文件。从某种意义上说,git不会以某种方式知道它们 - 它只关心你告诉你的文件。 –

0

我要恢复的本地目录完全一样,最后时间提交。在下图中,当地未提交的修改损坏

如果你要放弃你的本地提交的更改然后做reset HEAD(回到上次提交)

$ git reset --hard HEAD