【问题标题】:Remove Files completely from git repository along with its history从 git 存储库中完全删除文件及其历史记录
【发布时间】:2016-01-31 15:31:35
【问题描述】:

我在几次更新前上传了一个我无权分发到 git hub 的字体文件。

我有一个相对不活跃的存储库,如有必要,我可以通知我的所有成员。我已经尝试了几种解决方案。我需要在我的目录中删除一个名为Resources\Video\%font%.ttf 的文件,其中%font% 是字体的普通、斜体和粗体版本的名称。我使用什么命令?

【问题讨论】:

    标签: git bitbucket delete-file


    【解决方案1】:

    在这种情况下,您可以使用带有--tree-filter 选项的Git Filter Branch 命令。

    语法是git filter-branch --tree-filter <command> ...

    git filter-branch --tree-filter 'rm -f Resources\Video\%font%.ttf' -- --all
    

    编辑更新

    注意git filter-branch --index-filter--tree-filter 快很多

    git filter-branch --index-filter 'rm -f Resources\Video\%font%.ttf' -- --all
    

    在 windows 中必须使用 / 而不是 \


    命令说明:

    < command > 指定任何 shell 命令。

    --tree-filter:Git 将检查每个提交到工作目录,运行您的命令,然后重新提交。

    --index-filter:Git 更新 git 历史记录而不是工作目录。

    --all:过滤所有分支中的所有提交。

    注意:请检查您的文件路径,因为我不确定文件路径

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      根据官方 git 文档,使用git filter-branchis strongly discouraged,推荐的方法是使用贡献的git-filter-repo 命令。

      Install 它(通过包,或使用包 python3-pip,执行pip install)。

      驱魔命令filenameis then

      git filter-repo --invert-paths --path filename
      

      --invert-paths 选项表示排除,不包括以下路径。

      【讨论】:

        【解决方案3】:

        git filter-branch --index-filter 'git rm --cached --ignore-unmatch Resources\Video\%font%.ttf' HEAD 可以比--tree-filter 快​​很多(高达 100 倍),因为它只更新 git 历史记录而不是工作目录。

        参考:What is the difference between "--tree-filter" and "--index-filter" in the "git filter-branch"?
        参考:https://git-scm.com/docs/git-filter-branch

        【讨论】:

          猜你喜欢
          • 2019-03-17
          • 2021-01-09
          • 1970-01-01
          • 2011-05-29
          • 1970-01-01
          • 2012-04-21
          • 2011-10-16
          相关资源
          最近更新 更多