Skip to content

Instantly share code, notes, and snippets.

@eloyesp
Created May 17, 2022 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eloyesp/07421a50945ca94036013f2af7c61a24 to your computer and use it in GitHub Desktop.
Save eloyesp/07421a50945ca94036013f2af7c61a24 to your computer and use it in GitHub Desktop.
Cleanup a branch from layouthub
# generate the diff
git diff --stat main > to_clean.stat
# remove everything you want to KEEP
vim to_clean.stat
# Filter
git filter-branch --index-filter "cat $(pwd)/to_clean.stat |
xargs git rm --cached --ignore-unmatch" \
main..HEAD
# remove empty commits
git rebase -i main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment