我想撤消我的git拉的帐户上不需要的提交远程原点,但我不知道我必须重置回哪个修订。
我怎么能回到git拉远端原点之前的状态呢?
我想撤消我的git拉的帐户上不需要的提交远程原点,但我不知道我必须重置回哪个修订。
我怎么能回到git拉远端原点之前的状态呢?
当前回答
从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 origin/master
找到你想要提交的<SHA#>。你可以在github中找到它,或者在命令行输入git log或git reflog show,然后do git reset——hard <SHA#>
或者让它比另一个答案更明确:
git pull
哎呦?
git reset --keep HEAD@{1}
1.7.1以上版本的git没有——keep。如果您使用这样的版本,您可以使用—很难—但这是一个危险的操作,因为它会丢失任何本地更改。
致评论者
ORIG_HEAD是HEAD的先前状态,由可能有危险行为的命令设置,以便于恢复它们。现在Git有reflog: HEAD@{1}大致相当于ORIG_HEAD (HEAD@{1}总是HEAD的最后一个值,ORIG_HEAD是危险操作前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