git 使用中如何回滚提交, 撤销提交 How to undo the last commit?

回滚前言

本来在stackoverflow里面回答过了, 但是经常有同事在旁边问, 于是觉得有必要搬到这里, 并且做了一下翻译.

回滚上次提交正文

Just undo the last commit://只撤销上次的提交

git reset –soft HEAD~git reset –hard HEAD^

Or//或者

undo the last commit://回滚上次提交

git reset –soft HEAD~1

回滚上上次的提交

undo the time before last time commit://回滚上上次的提交

git reset –soft HEAD~2
… git reset –soft HEAD~2

Or

回滚之前的任意提交

you can undo any previous commit ://你可以回滚之前的任意提交

git reset –soft <commitID>
and commitID you git reset –soft <commitID>

(you can get by the command: commitID using git reflog)//关于commitID可能通过git reflog获得

git reflog

by the way, when When you undo a previous commit, remember to clean the workplace: with git clean.

当你回滚完毕后, 记得

清一下工作环境

git clean

更多细节

more More details can be found in the docs:

Git – git-reset Documentation

http://git-scm.com/docs/git-reset

对了, 在stackoverflow的回答如下

git – How to undo the last commit? – Stack Overflow
http://stackoverflow.com/questions/927358/how-to-undo-the-last-commit/30118831#30118831



Yol出品 http://www.paymoon.com/index.php/2015/06/10/git-how-to-und…he-last-commit/

 

发表评论

电子邮件地址不会被公开。