Skip to content

Instantly share code, notes, and snippets.

@schneefisch
Last active September 14, 2020 09:12
Show Gist options
  • Save schneefisch/c88103aeb1110114ebf985cac8983b38 to your computer and use it in GitHub Desktop.
Save schneefisch/c88103aeb1110114ebf985cac8983b38 to your computer and use it in GitHub Desktop.
remove the history of a git-repo
# Case:
# The git-repo is enourmous an we want to drop a part of the history
# or, if we split a monolithic application, and the "new" application emerging from it should only have a few commits and not the whole history.
#
git checkout --orphan temp $1 # create a new branch without parent history
git commit -m "Truncated history" # create a first commit on this branch
git rebase --onto temp $1 master # now rebase the part of master branch that we want to keep onto this branch
git branch -D temp # delete the temp branch
# The following 2 commands are optional - they keep your git repo in good shape.
git prune --progress # delete all the objects w/o references
git gc --aggressive # aggressively collect garbage; may take a lot of time on large repos
####
# then upload / push the files to a "new" repository
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment