I didn't encounter Git until the end of high school and it wasn't until a few years later that I actually understood how to use it properly. One of the biggest things I missed was the power of
.gitignore. This lead to many wayward
gen/ commits and unnecessarily large repositories.
Fast forward to the present predicament: bulk cleaning of past commits.
.gitignorefile you should have way back when.
Github .gitignore Collection
Base OS .gitignore Sample
<li> Apply the new <code>.gitignore</code> rules to all commits:<br /> <pre>git filter-branch --force --index-filter \
'git ls-files -ci --exclude-from=/path/to/repository/.gitignore -z | xargs -0 git rm --cached'
--prune-empty --tag-name-filter cat -- --all
If Git does not allow you to use the
.gitignore file from within the repository then you will need to copy it into a different directory, update the path in the sample, and re-run it.
See Reference section below for details on the above code sample
<li> Overwrite remote repository:<br /> <code>git push origin --force --all</code> </li> <li>[<i>Optional</i>] Add Git alias to apply <code>.gitignore</code> changes in the future<br /> Open Git configuration file <code>vi ~/.gitconfig</code><br /> If the <code>alias</code> section does not exist, you will need to add it. <pre>[alias] apply-gitignore = !git ls-files -ci --exclude-standard -z | xargs -0r git rm --cached</pre> Save your changes
Github Help: Purging a File from Repository History
stackoverflow: Applying .gitignore to Committed Files