代码之家  ›  专栏  ›  技术社区  ›  Ben Vessely

Git筛选器仓库未从提交历史中删除文件

  •  1
  • Ben Vessely  · 技术社区  · 1 年前

    今天我意识到,大约一周前(大约10次提交前),我意外地向git提交了一个(轻度)私有文件,该文件不应保留在我的git提交历史中。我决定使用git filter repo来尝试删除该文件,但我遇到了问题。

    我开始跑步

    git filter-repo --path credentials.ini  --invert-paths
    

    但这不起作用,因为我没有新的仓库克隆。然后我意识到我从未将我的存储库推送到远程,所以我只是将整个存储库复制到本地计算机上,以备过滤器存储库不起作用时作为备份。然后我运行

    git filter-repo --path credentials.ini  --invert-paths --force
    

    之后终端输出

    Parsed 24 commits
    New history written in 0.06 seconds; now repacking/cleaning...
    Repacking your repo and cleaning out old unneeded objects
    HEAD is now at a72b0d4 Submit now doesn't work if there are any notes (i.e. errors). Bug still exists with submitting without refocusing first
    Enumerating objects: 167, done.
    Counting objects: 100% (167/167), done.
    Delta compression using up to 8 threads
    Compressing objects: 100% (143/143), done.
    Writing objects: 100% (167/167), done.
    Total 167 (delta 49), reused 41 (delta 11), pack-reused 0
    Completely finished after 0.23 seconds.
    

    然后我用 git log --stat 检查文件是否仍然存在,并且确实存在。Git还通过至少一次提交重置了我的HEAD(也许是最近的一次提交,我不确定),我有点担心在这一点上会丢失我的提交历史记录,所以我只是把所有东西推到我的远程 https://github.com/benvessely/brevets (commit以6d31a开头,文件是credentials.ini,以防有帮助)。我在github上检查了一下,credentials.ini文件似乎也在那里,所以这不仅仅是因为该文件出现在我的工作树上,而且实际上并没有从提交历史记录中删除。然后我跑了 git filter-repo --path credentials.ini --invert-paths --force 再次以防万一,但一切都没有改变。

    This 这个问题和我有类似的问题,但似乎他们只是在没有真正弄清楚问题所在的情况下解决了。

    感谢您提供的任何帮助!

    1 回复  |  直到 1 年前
        1
  •  0
  •   matt    1 年前

    问题是文件的路径是 credentials.ini 确实如此 brevets/credentials.ini .

    推荐文章