Monday, April 15, 2013

GIT history cleanup

# 1. Remove temp files of Maven-release-plugin from overall GIT history:
git filter-branch --tree-filter 'find . \( -name "pom.xml.releaseBackup" -o -name "release.properties" \) -exec rm -rf {} \;'

# 2. Remove Java *.class files from overall GIT history:
git filter-branch --tree-filter 'find . \( -name "*.class" \) -exec rm -rf {} \;'

# 3. Remove Java Checkstyle .checkstyle files and Eclipse .settings files from overall GIT history:
git filter-branch --tree-filter 'find . \( -name ".checkstyle" -o -name ".settings" \) -exec rm -rf {} \;'


# 4. Change user nickname to 'First Name Last name' in overall GIT history
git filter-branch --env-filter \
'
if [ "$GIT_AUTHOR_NAME" = "dyaroslavtsev" ];
then
  export GIT_AUTHOR_NAME="Daniil Yaroslavtsev"
fi
'

# After 1,2,3, or 4 you should to delete the backup reflogs to reclaim the space (although now the operation is destructive):
git reset --hard
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# You also should to clean repo with all reflogs with 'git gc' command using its 'aggressive' mode
git reflog expire --expire=now --all
git gc --aggressive --prune=now

No comments:

Post a Comment