Book Image

Git Version Control Cookbook

By : Aske Olsson, Rasmus Voss
Book Image

Git Version Control Cookbook

By: Aske Olsson, Rasmus Voss

Overview of this book

Table of Contents (19 chapters)
Git Version Control Cookbook
About the Authors
About the Reviewers

Revert – undo the changes introduced by a commit

Revert can be used to undo a commit in history that has already been published (pushed), whereas this can't be done with the amend or reset options without rewriting history.

Revert works by applying the anti-patch introduced by the commit in question. A revert will, by default, create a new commit in history with a commit message that describes which commit has been reverted.

Getting ready

Again, we'll use the hello world repository. Make a fresh clone of the repository, or reset the master branch if you have already cloned.

We can create a fresh clone as follows:

$ git clone
$ cd hello_world_cookbook

We can reset the existing clone as follows:

$ cd hello_world_cookbook
$ git checkout master
$ git reset --hard origin master
HEAD is now at 3061dc6 Adds Java version of 'hello world'

How to do it...

  1. First, we'll list the commits in the repository:

    $ git log --oneline
    3061dc6 Adds Java version of...