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

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


原文地址:http://stackoverflow.com/questions/8358035/whats-the-difference-between-git-revert-checkout-and-reset

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.


相关文章推荐

Undoing in Git - Reset, Checkout and Revert

Undoing in Git - Reset, Checkout and Revert Git provides multiple methods for fixing up mistakes ...
  • xqs83
  • xqs83
  • 2012年03月22日 12:41
  • 1166

git撤销大全(reset、reflog、revert、checkout、rebase、rm)

注:本文翻译自这里撤销“public”修改场景:你使用git push将本地更改发布到github上,突然意识到这个commit有点问题,不能push上去,你需要撤销这个commit。撤销: gi...
  • bdss58
  • bdss58
  • 2015年12月20日 16:22
  • 1496

What's difference between PMP and PRINCE2

There’s a post over at PM Student by Dr Paul Giammalvo comparing project management certifications. ...

What's the difference between windowBackground and background for activities style?

What's the difference between windowBackground and background for activities style? From: http://...
  • fyfcauc
  • fyfcauc
  • 2015年03月04日 15:59
  • 249

What's the difference between program arguments and VM arguments?

What's the difference between program arguments and VM arguments? Author: Deron Eriksson Description...
  • pfyuit
  • pfyuit
  • 2012年04月27日 22:32
  • 405

PS笔记:What's the difference between Subexpression and Array Subexpression?

关于powershell的细节十分的多,作为回顾和总结,今天我们要说的是关于子表达式(Subexpression)和数组子表达式(Array Subexpression)的区别。先来简单介绍下 两者表...

What's the difference between UTF-8 and Unicode?

If asked the question, "What is the difference between UTF-8 and Unicode?", would you confidently re...

What's+the+difference+between+virtualization+and+cloud+computing?

在很多资料或文献中很难找到虚拟化和云计算的区别,甚至连云计算是什么都颇有争议。在网上找到几片论述这一问题的文章,摘录于下。 1. Cloud is an operations model, ...
  • bonny95
  • bonny95
  • 2011年10月13日 15:59
  • 896

What's the difference between CUDA shared and global memory?

What's the difference between CUDA shared and global memory? 1.When we use cudaMalloc() In order to...
  • ywcpig
  • ywcpig
  • 2015年05月28日 20:08
  • 335

What's the difference between “local” and “my” in Perl

There are two kinds of variable scopes in Perl: Global variables: They reside in the current pa...
  • ThinkHY
  • ThinkHY
  • 2012年08月30日 12:55
  • 1404
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:What's the difference between Git Revert, Checkout and Reset?
举报原因:
原因补充:

(最多只允许输入30个字)