文章版本: Enterprise Server 2.17
从仓库的历史记录中删除文件
要从仓库中删除大文件,必须将其从本地仓库和 您的 GitHub Enterprise Server 实例 中完全删除。
警告:这些步骤将从您的计算机和 您的 GitHub Enterprise Server 实例 上的仓库中永久删除文件。 如果文件很重要,请在仓库外部的目录中创建本地备份副本。
Removing a file that was added in an earlier commit
If you added a file in an earlier commit, you need to remove it from the repository's history. To remove files from the repository's history, you can use the BFG Repo-Cleaner or the git filter-branch
command. For more information see "Removing sensitive data from a repository."
删除在最近未推送的提交中添加的文件
如果文件使用最近的提交添加,而您尚未推送到 您的 GitHub Enterprise Server 实例,您可以删除文件并修改提交:
- 打开 Terminal(终端)Terminal(终端)Git Bash。
- 将当前工作目录更改为您的本地仓库。
- 要删除文件,请输入
git rm --cached
:$ git rm --cached giant_file # Stage our giant file for removal, but leave it on disk
- 使用
--amend -CHEAD
提交此更改:$ git commit --amend -CHEAD # Amend the previous commit with your change # Simply making a new commit won't work, as you need # to remove the file from the unpushed history as well
- 将提交推送到 您的 GitHub Enterprise Server 实例:
$ git push # Push our rewritten, smaller commit