What's the difference between Git Revert, Checkout and Reset?

转载 2013年12月05日 11:16:33


These three commands have entirely different purposes. They are not even remotely similar.

git revert

This command creates a new commit that undoes the changes from a previous commit. This command adds new history to the project (it doesn't modify existing history).

git checkout

This command checks-out content from the repository and puts it in your work tree. It can also have other effects, depending on how the command was invoked. For instance, it can also change which branch you are currently working on. This command doesn't make any changes to the history.

git reset

This command is a little more complicated. It actually does a couple of different things depending on how it is invoked. It modifies the index (the so-called "staging area"). Or it changes what commit a branch head is currently pointing at. This command may alter history (by changing the commit that a branch references).

Using these commands

If a commit has been made somewhere in the project's history, and you later decide that the commit is wrong and should not have been done, then git revert is the tool for the job. It will undo the changes introduced by the bad commit, recording the "undo" in the history.

If you have modified a file in your working tree, but haven't committed the change, then you can use git checkout to checkout a fresh-from-repository copy of the file.

If you have made a commit, but haven't shared it with anyone else and you decide you don't want it, then you can use git reset to rewrite the history so that it looks as though you never made that commit.

These are just some of the possible usage scenarios. There are other commands that can be useful in some situations, and the above three commands have other uses as well.

git reset、checkout & revert 代码回滚

git reset 和 git checkout 即可以用于commit,也可以用于一个文件,而 revert只能用于commitgit revert:撤销某次commit的修改,并且自动新建一个co...
  • GW569453350game
  • GW569453350game
  • 2015年08月18日 16:37
  • 3615

What is the difference between arm-linux-gcc and arm-none-linux-gnueabi and arm-linux-gnueabi toolch

Toolchains have a loose name convention like arch[-vendor][-os]-abi.arch is for architecture: arm, m...
  • u010825025
  • u010825025
  • 2017年06月23日 16:55
  • 129

git reset与git revert比较

git resetgit reset的作用是还原Index的状态或修改本地分支HEAD的位置。这个命令适合用于从某个提交点重新开新的分支。比如,如果某个提交之后的代码我们都不要了,就可以在本地rese...
  • woxueliuyun
  • woxueliuyun
  • 2016年04月11日 15:30
  • 7234

git入门(5)-Git revert和git reset版本的回退

git revert 撤销 某次操作,此次操作之前和之后的commit和history都会保留,并且把这次撤销作为一次最新的commit,如果需要彻底回退,只需要将本次commit * gi...
  • codectq
  • codectq
  • 2016年03月02日 10:28
  • 6561

git reset revert rebase 区别

最近合并他人代码,因为代码是从git代码库之外来的,于是出了各种问题。于是又翻看了git教程。这里推荐两篇: Git教程 - 廖雪峰的官方网站 非常通俗易懂,教了最基本的,十分实用。 ###Git...
  • LaineGates
  • LaineGates
  • 2017年06月07日 11:09
  • 1060

git reset & checkout & revert

git-reset - Reset current HEAD to the specified stategit reset [-q] [] [--] …​ git reset (--patch | ...
  • claroja
  • claroja
  • 2017年11月07日 12:22
  • 163

Difference between hub, switch and router

What's the difference between a Hub, a Switch and a Router?•In a word: intelligence.Hubs, switches, ...
  • Andrew659
  • Andrew659
  • 2010年09月29日 21:21
  • 1137


最近用github做我的博客,有些时候会设置错误需要用撤回操作,这时就用到git revert与reset reset(版本撤回) 格式 git reset [-q] [] [--]...
  • z69183787
  • z69183787
  • 2015年07月02日 13:29
  • 3557

git checkout reset revert

总有一天你会遇到下面的问题: (1)改完代码匆忙提交,上线发现有问题,怎么办? 赶紧回滚. (2)改完代码测试也没有问题,但是上线发现你的修改影响了之前运行正常的代码报错,必须回滚. 这些开发中很...
  • qq_30534535
  • qq_30534535
  • 2016年08月01日 11:15
  • 188


  • caz28
  • caz28
  • 2015年02月07日 14:01
  • 1757
您举报文章:What's the difference between Git Revert, Checkout and Reset?