我想撤消我的git拉的帐户上不需要的提交远程原点,但我不知道我必须重置回哪个修订。

我怎么能回到git拉远端原点之前的状态呢?


当前回答

重置主分支:

git reset --hard origin/master

其他回答

git reflog show将显示HEAD的历史。你可以用这个查出你被拉之前在哪里。然后你可以重置你的HEAD到那个提交。

从https://git-scm.com/docs/git-reset文档/ git-reset.txt-Undoamergeorpullinsideadirtyworkingtree

Undo a merge or pull inside a dirty working tree $ git pull (1) Auto-merging nitfol Merge made by recursive. nitfol | 20 +++++---- ... $ git reset --merge ORIG_HEAD (2) Even if you may have local modifications in your working tree, you can safely say git pull when you know that the change in the other branch does not overlap with them. After inspecting the result of the merge, you may find that the change in the other branch is unsatisfactory. Running git reset --hard ORIG_HEAD will let you go back to where you were, but it will discard your local changes, which you do not want. git reset --merge keeps your local changes.

参见https://stackoverflow.com/a/30345382/621690

这对我很管用。

git reset --hard ORIG_HEAD 

撤销合并或拉取:

$ git pull                         (1)
Auto-merging nitfol
CONFLICT (content): Merge conflict in nitfol
Automatic merge failed; fix conflicts and then commit the result.
$ git reset --hard                 (2)
$ git pull . topic/branch          (3)
Updating from 41223... to 13134...
Fast-forward
$ git reset --hard ORIG_HEAD       (4)

在Git中签出这个:HEAD和ORIG_HEAD。

重置主分支:

git reset --hard origin/master

找到你想要提交的<SHA#>。你可以在github中找到它,或者在命令行输入git log或git reflog show,然后do git reset——hard <SHA#>