This will be a two-step procedure:
Introduce the .gitignore file
For this to work, the early commits are going to have to have your .gitignore
file. So, you need to:
- Check out the root commit:
git checkout -b temp $(git rev-list HEAD | tail -1)
- Add the
.gitignore
file.
git commit --amend
- Rebase all of your existing branches onto "temp". This may or may not work seamlessly, so you might need to fiddle with it if any conflicts spring up.
- Check out your working branch and delete the temp branch.
Rewrite history
Now you can automatically remove these files from all of the branches by this command:
git filter-branch --tree-filter 'git clean -f -X' -- --all
This will rewrite all of your branches to remove ignored files. It may take a while depending on the size of your repository.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…