Last active
January 10, 2019 23:55
-
-
Save jennings/f3b3f24285e38650c74c0b0d2db8bb77 to your computer and use it in GitHub Desktop.
Using the `--state-branch` option to `git-filter-branch` to incrementally filter a branch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -exuo pipefail | |
TRUNK=master | |
REWRITE_BRANCH=master-to-rewrite | |
NEW_BRANCH_BOOKMARK=master-filtered | |
LAST_IMPORT_BRANCH=master-lastimport | |
STATE=master-state | |
INDEX_FILTER_SCRIPT='git rm -r --cached --ignore-unmatch bad_directory' | |
# Update the trunk | |
git checkout -f $TRUNK | |
git clean -fd || true | |
git pull | |
# Prepare the branch to rewrite | |
git branch -D $REWRITE_BRANCH || true | |
git branch $REWRITE_BRANCH $TRUNK | |
# Go! | |
git filter-branch --index-filter "$INDEX_FILTER_SCRIPT" \ | |
--state-branch $STATE \ | |
--prune-empty \ | |
-f \ | |
$LAST_IMPORT_BRANCH..$REWRITE_BRANCH | |
git checkout $NEW_BRANCH_BOOKMARK | |
git merge --ff-only $REWRITE_BRANCH | |
# Cleanup | |
git checkout -f $LAST_IMPORT_BRANCH | |
git merge --ff-only $TRUNK | |
git checkout $TRUNK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment