How to delete files from git bare remote repository?

淺唱寂寞╮ 提交于 2019-12-07 02:13:13

问题


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:

  1. 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)
  2. Push your changes back to the remote repository using git push --force.
  3. 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:

  1. 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

  2. Force push to remote.

    $ git push origin master --force

  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!