47

Github for Windows features these two commands described as:

  1. revert this commit - create a new commit that reverts the changes of this commit
  2. rollback this commit - roll back this commit leaving all changes made in this and later commits in your working directory

Could you explain the exact meaning of these two commands and how they can be used. Specifically I fail to understand what is the purpose of the second one. It makes no sense to me.

Is it possible to revert to a previous commit check it out and if I don't like it, go back to where it was initially?

This gui seems to feature a very small part of the git system but what would be a proper workflow utilizing it?

Toph
  • 2,561
  • 2
  • 24
  • 28
Zingam
  • 4,498
  • 6
  • 28
  • 48
  • 1
    Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – jub0bs Sep 25 '14 at 19:00

2 Answers2

64

Suppose you have a single file in your repo, and you have the following commits:

commit 1 : the file contains A
commit 2 : the file contains B
commit 3 : the file contains C

If you execute revert on commit 3, you'll have this in the repo:

commit 1 : the file contains A
commit 2 : the file contains B
commit 3 : the file contains C
commit 4 : the file contains B

And the file in your working copy will contain B as well.

If you execute roll back, you'll have this in the repo:

commit 1 : the file contains A
commit 2 : the file contains B

And the file in your working copy will be left unmodified. The file will thus contain C. It allows you to fix a small mistake and commit again, for example.

BoydDensmore
  • 181
  • 12
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • So I would basically delete the commit but no files would be changed? What would be the purpose of that? If I name a commit: "BBbbadd spppelling" and then I notice my mistake that would be the way I fix it. Or there is more to it? – Zingam Feb 23 '13 at 14:42
  • 1
    Yes. Why don't you experiment and see what happens? – JB Nizet Feb 23 '13 at 14:43
  • Actually I am experimenting right now but I wasn't quite sure what exactly happens :) I think that I get it now finally. I couldn't find any "Help/Wiki" about the function of these two commands. Thank you! – Zingam Feb 23 '13 at 14:49
  • 2
    The second command just move the `HEAD`, so you may explain it. – prehistoricpenguin Aug 13 '13 at 01:23
  • 4
    It's probably worth noting that [`git reset --hard `](http://git-scm.com/docs/git-reset) will rollback the repo and and the working copy to the `old-commit-id` provided. Whereas using the `--soft` option will only change the HEAD and leave your working copy unchanged. – KyleMit Jun 12 '14 at 01:05
13

Is it possible to revert to a previous commit check it out and if I don't like it, go back to where it was initially?

It is now (March 2013), with GitHub for Windows, you can undo a rollback without having to type any git command:

See "Undo Button in GitHub for Windows"

we've added Undo support for Discards, Commits, Rollbacks, and Merges:

Undo button

Emil Laine
  • 41,598
  • 9
  • 101
  • 157
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250