Git tricks

  • Posted on: 28 April 2016
  • By: Michał Turecki

Inspired by spring cleaning of a collection of "New Text Document (n).txt" files on my desktop I decided to prepare a collection of git useful scripts, yet another. Here is the list:

  1. Replace git commit user name and email address in a branch history:

    #!/bin/sh
    
    git filter-branch --env-filter '
    OLD_EMAIL="not@used.anymore"
    CORRECT_NAME="My Name"
    CORRECT_EMAIL="my@new.email"
    if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
    then
        export GIT_COMMITTER_NAME="$CORRECT_NAME"
        export GIT_COMMITTER_EMAIL="$CORRECT_EMAIL"
    fi
    if [ "$GIT_AUTHOR_EMAIL" = "$OLD_EMAIL" ]
    then
        export GIT_AUTHOR_NAME="$CORRECT_NAME"
        export GIT_AUTHOR_EMAIL="$CORRECT_EMAIL"
    fi
    ' --tag-name-filter cat master --branches --tags