2012-11-13 109 views
0

我想恢復到特定的提交ID。還原文件我「git rm」-ed。從此吹掉所有提交的提交。然後提交回購。我將如何做到這一點?撤消一堆Git混亂

回答

2
$ git reset --hard <commit ID> # Will reset to a specific commit 
$ git push -f <remote>   # Push branch into remote, with force 

注意,任何人誰克隆你的回購可能會遇到一些小問題,如果他們只是在更改拉(因爲你被迫向後跳轉在提交歷史);他們應該這樣做是爲了讓您的更改:

$ git fetch <remote> 
$ git reset --hard <remote>/<branch> 

注意,這也將吹走的他們改變當前分支。但是,如果他們有任何由他們當前分支製作的分支,那些分支仍然會有您「吹走」的提交。

+0

有些人認爲'push -f'是犯罪! –

+0

如果你知道自己在做什麼,在某些情況下它很有用。 – mipadi

0

也許您在尋找git reset --soft {ID}

git reset --<mode> [<commit>] 
     This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>, which must be one of the 
     following: 

     --soft 
      Does not touch the index file nor 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. 

不知道什麼是打擊」的真正含義,那爲什麼--hard模式可能是有用的。

0

您可以使用混帳復歸my_commit_id命令。

如果它是一個或兩個以前提交,你分別使用git revert HEADgit revert HEAD^

而不是HEAD使用你的提交ID,如果這不能解決你的情況

這也會給你一個選項來再次編輯提交messg並創建新的提交。 `