Is there a simple way to remove unwanted file from Github history?

心已入冬 提交于 2019-12-06 15:28:41

问题


I have spend half an hour reading questions and answers and still I didn't find a simple way to do this. So, is there an easy way to remove unwanted file from Github history (just to name the file and delete it)?


回答1:


As @VonC says, GitHub doesn't provide the ability to remove files from history through their UI. As an outsider, this would be my view on why that's so:

  • Once the data is up on GitHub, it's already too late in some sense. If the data is private then putting it on GitHub has already compromised that privacy. If the data is just really big, GitHub already has filters in place to stop any file bigger than 100MB being pushed up.
  • Rewriting history (especially to remove data) is obviously very destructive & disruptive - the kind of thing you don't necessarily want to make easy. If they did include it, they'd have to surround it with ugly confirmation are-you-really-sure dialogs.
  • Until I created the BFG, the main tool for removing files from git history was git filter-branch, which is very slow on big repos - GitHub would have had to chuck these clean-up jobs on to a long-running queue, and tell you to come back later. In the case of a big repo, it could have taken days to complete the job.

Given all that, it's quite reasonable that GitHub don't support it themselves. You are expected to do it yourself from the command-line- but it's not that hard, I wrote the BFG to make this process simple:

bfg --delete-files myBad.mp3

...the BFG is now recommended by GitHub, Atlassian, and also in the docs for git filter-branch itself.

Incidentally, Git is the underlying source-control software, GitHub is a company that provides hosted-Git (so you're rewriting Git history, rather than GitHub history really).

Full disclosure: I'm the author of the BFG Repo-Cleaner.




回答2:


Not from GitHub directly.

You would still have to clone it locally, clean it (with BFG for instance, faster than the git filter-branch), and push it back.
The push would be a force one git push --force, which means you need to notify other users of that repo, for them to reset their own clone.

For instance (with bfg: "Cleaning Up Git Repositories With The BFG Repo-Cleaner"):

bfg --delete-files id_{dsa,rsa}  my-repo.git


来源:https://stackoverflow.com/questions/27761031/is-there-a-simple-way-to-remove-unwanted-file-from-github-history

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