docs:git:filter-branch

git filter-branch

git filter-branch allows you to rewrite history of any size. For example, you could change the author's name and email for an entire project. However, this will change the SHA-1 so you can't do this if other people are tracking your project or branch.

You can change various things conditionally, and if you don't change anything then the commit will go in exactly as it was before.

  • -d <dirname> represents where git will temporarily put the work as the new commits are created
#!/bin/bash
 
git filter-branch --env-filter '
  if [ $GIT_COMMIT = "97de3480e040f575bf9615162b197af426cab712" ]; then
	dt="2005.01.01 00:00:00"
    export GIT_AUTHOR_DATE=$dt
    export GIT_COMMITTER_DATE=$dt
  fi
  if [ $GIT_COMMIT = "827e1b8b64e37c7eebb1033ce66442ca9397e878" ]; then
	dt="2006.02.01 00:00:00"
    export GIT_AUTHOR_DATE=$dt
    export GIT_COMMITTER_DATE=$dt
  fi
  if [ $GIT_COMMIT = "856b9dcc2100bd0c0fe8309023086a32ab582bf5" ]; then
	dt="2007.03.01 00:00:00"
    export GIT_AUTHOR_DATE=$dt
    export GIT_COMMITTER_DATE=$dt
  fi
  if [ $GIT_COMMIT = "0cbae41340cbc803eca684e8ad6394af679faa53" ]; then
	dt="2008.04.01 00:00:00"
    export GIT_AUTHOR_DATE=$dt
    export GIT_COMMITTER_DATE=$dt
  fi
' -d tmp \
HEAD
git filter-branch --msg-filter '
        sed -e "/^git-svn-id:/d"
'
  • docs/git/filter-branch.txt
  • Last modified: 2010/04/14 22:53
  • by billh