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 --cached
the extra files locally (note the --cached
option to keep those files in your working directory),.gitignore
file and git 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 --cached
the files, then replay the other commmits unless some of them have also made modifications to the same files.git filter-branch
or git rebase
),git rebase
man page).push -f
to forcefully revert the remote backwards (WARNING: This will "break" repositories which have those commits already pulled - its undoable, but manual drudgery). Well add them to .gitignore
(line separated filenames in the main directory of the repo and then follow this guide: http://help.github.com/removing-sensitive-data/. Finally git push -f
to forcibly overwrite the remote repo.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With