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

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


当前回答

这对我很管用。

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拉取

git reset --hard HEAD^

将本地回购恢复到以前的提交状态。(注意:HEAD^表示当前分支顶端的第一个直接父结点。HEAD^是HEAD^1的缩写,如果你想,你也可以进一步往上(例如HEAD^2, HEAD^3…) 重置后,如果留下一些未知文件(由于原始git拉取而到达的文件),它们将被列为未跟踪文件,您可以使用

  git clean -fd

从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

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

这对我很管用。

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