Git Reset

git reset reverts changes by moving a branch reference backwards in time to an older commit. In this sense you can think of it as "rewriting history;" git reset will move a branch backwards as if the commit had never been made in the first place.

我们来执行一个命令:

git reset HEAD~1

执行前:

屏幕快照 2013-05-20 下午3.19.29

执行后:

屏幕快照 2013-05-20 下午3.20.44

Nice! Git simply moved the master branch reference back to C1; now our local repository is in a state as if C2 had never happened

------------------------------------------------------------------------------------------------------------------------------

Git Revert

While reseting works great for local branches on your own machine, its method of "rewriting history" doesn't work for remote branches that others are using.

In order to reverse changes and share those reversed changes with others, we need to use git revert.

我们来执行一个命令:

git revert HEAD

执行前:

屏幕快照 2013-05-20 下午3.19.29

执行后:

屏幕快照 2013-05-20 下午3.23.40

Weird, a new commit plopped down below the commit we wanted to reverse. That's because this new commit C2' introduces changes -- it just happens to introduce changes that exactly reverses the commit of C2.

With reverting, you can push out your changes to share with others.

------------------------------------------------------------------------------------------------------------------------------

两者的差别总结

reset只能用于本地,可以完全回退一次、或几次提交,并完全不留下任何记录。而revert可用于远程服务器,在回退的过程中,会留下提交痕迹。