User login

Git revert a commit

To revert a very simple commit, this is enough:

git revert ba24a3fdeae4a3a034691308171d798d2ddbf93e

Where that long string of characters is the ID of the commit you are reverting.

For a more careful approach to a complex revert, read on...

(if things go horribly wrong we can throw out this branch-- note we may have to commit everything in the branch in order to switch to another branch and delete this one with git branch -D revert-alpha-6

This approach worked:

Based in part on http://www-cs-students.stanford.edu/~blynn/gitmagic/ch02.html#_reverting

Note: "git revert" makes a commit with the revert for us.

To tell us what we want to revert, we use git log:

git log


commit e93d009d4ae28006c4dadc3ad594c83c23c75c10
Author: Benjamin Melançon ben@agaric.com
Date: Sun Jul 11 09:25:39 2010 -0700

Completion of upgrade to Drupal 7 Alpha 6 required a custom module, do it fi

commit 66d296bd6aaf09031329348db22e283d77476747
Author: Benjamin Melançon ben@agaric.com
Date: Sun Jul 11 09:24:02 2010 -0700

Upgrade to Drupal 7 alpha 6 using a diff method.

git checkout -b revert-alpha-6 master

git revert e93d009d4ae28006c4dadc3ad594c83c23c75c10
git revert 66d296bd6aaf09031329348db22e283d77476747

git checkout master
Switched to branch 'master'

git merge revert-alpha-6

(see a bunch of content go by, and make sure everything is set by checking that git diff master..revert-alpha-6 returns nothing).

This approach failed when i tried to do two reverts in a row

But i stole other elements of the branching and committing process around doing the revert from this tutorial.

From http://www.kernel.org/pub/software/scm/git/docs/howto/revert-branch-rebase.html

git show-branch --more=4 master master^2 | head

! [master] Merge branch 'master' of git.agaric.com:/srv/git/dgd7

! [master^2] added my dgd7 bartik subtheme

  • [master] Merge branch 'master' of git.agaric.com:/srv/git/dgd7
    ++ [master^2] added my dgd7 bartik subtheme
  • [master^] Git ignore that ignores some devel modules too.
  • [master~2] Completion of upgrade to Drupal 7 Alpha 6 required a custom module, do it first next time. See http://data.agaric.com/raw/upgrading-from-drupal-7-alpha-drupal-7-alpha
  • [master~3] Upgrade to Drupal 7 alpha 6 using a diff method.
    ++ [master~4] My patch to fix insert module based on object to entity name change figured out by original poster.

Other reference

http://book.git-scm.com/3_basic_branching_and_merging.html

Searched words: 
git revert commit git delete branch git delete branch currently on with merge git revert specific commit

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.