2017-02-23 85 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