I erroneously added some local project files to a git repository and committed/pushed them.
I’d like to delete these files from the remote repository, keep them locally, and ignore them for future commits/pushes.
What’s the best way to go about this?
The cleanest solution is the following:
git rm --cachedthe extra files locally (note the--cachedoption to keep those files in your working directory),.gitignorefile andgit commit -A -m "..."after that,If you think not too many people have pulled from your remote repo (ideally, none), you could:
(
git rebase --interactive first-commit-with-files^: the ‘^’ referencing the parent commit of the first one where you did introduce the bad files.git rm --cachedthe files, then replay the other commmits unless some of them have also made modifications to the same files.Other solutions here —
git filter-branchorgit rebase),(but then, be prepared to point out people to the RECOVERING FROM UPSTREAM REBASE section of the
git rebaseman page).(see definition of upstream here)