问题
I have a remote bare git repository.
A new developer cloned it, but he didn't have a properly configured .gitignore file, so he mistakenly pushed some unwanted files into the remote. When I pulled the changes and merged, I got these previously untracked files. Others have also pulled the changes from the remote and have these unwanted files as well.
How do I delete these files from the remote repository, and everyone else's remote/origin/branches?
回答1:
This is a three step process:
- Remove the files from your copy of the repository (either with git rm or by totally purging these files from your history depending on how important it was that these files never be in the repository in the first place)
- Push your changes back to the remote repository using git push --force.
- Let everyone know that they can re-pull the repository - this will require a git rebase of their work on the last know good commit.
As a last step you may also want to add the .gitignore
file to the repository so that when the repository is cloned all the right files get ignored.
回答2:
See github have a FAQ on this: https://help.github.com/articles/remove-sensitive-data Here are the steps:
Rewrite the tree from local (working) tree.
$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch Rakefile' \ --prune-empty --tag-name-filter cat -- --all
Force push to remote.
$ git push origin master --force
Everybody pull from the remote (and use
--force
if needed)
To prevent this from happening again, you should check the .gitignore
in the repository (and optionally setup a hook on server)
来源:https://stackoverflow.com/questions/12311330/how-to-delete-files-from-git-bare-remote-repository