2012-11-13 95 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并创建新的提交。 `