Skip to content

Instantly share code, notes, and snippets.

@rpavlik
Last active October 11, 2019 05:15
Show Gist options
  • Save rpavlik/6346fc02ff86649a2933 to your computer and use it in GitHub Desktop.
Save rpavlik/6346fc02ff86649a2933 to your computer and use it in GitHub Desktop.
Extreme git filter-branch: keep only one or a few files
# Based on <http://git.661346.n2.nabble.com/Remove-all-files-except-a-few-files-using-filter-branch-td7567155.html>
# for most of it (the index filter part) and on this SO answer for how to get rid of the many meaningless commits now:
# <http://stackoverflow.com/a/5326065/265522>
git filter-branch --index-filter "git rm --cached -qr -- . && git reset -q $GIT_COMMIT -- THEFILEYOUWANTTOKEEP" # --prune-empty
git filter-branch --commit-filter 'git_commit_non_empty_tree "$@"'
@bcip
Copy link

bcip commented Oct 11, 2019

I find this script only keep files but not the history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment