Using git to re-apply an old over-written change

Benjamin Melançon's picture
Submitted by Benjamin Melançon on 2010, December 20 - 12:33

Tags

  • [Searched words]
    filter a git log
    filter log output command line
    grep git history
    git view commit
    git re-apply commit

    To do a simple search through Git's commit messages (another reason to write useful information when committing!) *and* the accompanying diffs, you can use to search for dgd7.org:

    git log -Sdgd7.org

    Shows us, as one of a few matches:

    commit 89bec60d085839fff22fdd4e387063717282edc6
    Author: Benjamin
    Date: Tue Jun 15 19:47:23 2010 -0400

    .htaccess for live site with redirects of all aliased domain names.

    To view the changes made (diff), we only need the first characters of the commit hash:
    git show 89bec60

    It's the right one:

    commit 89bec60d085839fff22fdd4e387063717282edc6
    Author: Benjamin
    Date: Tue Jun 15 19:47:23 2010 -0400

    .htaccess for live site with redirects of all aliased domain names.

    diff --git a/drupal/.htaccess b/drupal/.htaccess
    index e673753..60d5c26 100644
    --- a/drupal/.htaccess
    +++ b/drupal/.htaccess
    @@ -62,6 +62,9 @@ DirectoryIndex index.php index.html index.htm

    RewriteEngine on

    + RewriteCond %{HTTP_HOST} ^(www\.|)(definitivedrupal.com|dgd7.com|dgd7.org|dgd
    + RewriteRule ^(.*)$ http://definitivedrupal.org/$1 [L,R=301]
    +
    # Block access to "hidden" directories whose names begin with a period. This
    # includes directories used by version control systems such as Subversion or
    # Git to store control files. Files whose names begin with a period, as well

    To reapply this commit automatically, we use Git's cherry-pick command, which applies it as a patch and immediately commits it with the same commit message):
    git cherry-pick 89bec60

    And we're done!

  • Explanation

  • Maybe this could go in the deployment chapter/appendix.
  • Book element

  • Concept