撤消一堆Git一塌糊涂

时间:2012-11-13 17:50:22

标签: git

我想恢复到特定的提交ID。恢复文件我“git rm”-ed。吹掉从那时起所做的所有承诺。然后提交回购。我该怎么做?

3 个答案:

答案 0 :(得分: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>

请注意,这也会消除当前分支中他们的更改中的任何内容。但是,如果他们的当前分支有任何分支,那么这些分支仍然会有你“被吹走”的提交。

答案 1 :(得分: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模式也很有用。

答案 2 :(得分:0)

您可以使用 git revert my_commit_id 命令。

如果是一次或两次之前的提交,则分别使用git revert HEADgit revert HEAD^

如果这不能解决您的问题,请使用您的提交ID代替HEAD。

这也将为您提供再次编辑commit messg并创建新提交的选项。 `