如何从Git历史中移除文件而不使历史分叉?

huangapple go评论59阅读模式
英文:

How to remove file from git history without diverging the history?

问题

开发者A(原作者)创建了一个仓库。他在初始提交中包含了一个大的二进制文件。
开发者B(我)创建了一个分支并提交了删除该二进制文件的更改(但它仍然保留在历史记录中)。之后,B对该分支进行了更多的更改,而A的仓库保持不变。
B如何在不创建完全不同的提交历史记录与A的仓库的情况下删除该文件(我可以接受几个不同的提交历史记录)?或者至少在克隆仓库时禁用对该二进制文件的自动克隆。

我尝试过git filter-branchgit-filter-repogit rebase -i。它们都会创建不同的提交历史记录。

英文:

Let's say developer A (original author) creates a repository. He makes an initial commit in which he includes big binary file.
Developer B (me) creates a fork and commits removal of that binary (it still stays in history). After that B makes more changes to the fork, while A's repo remains untouched.
How can B remove the file from history without creating completely diverging histories with A's repo (I'm ok with several diverging commits)? Or at least disable automatic cloning of that binary when cloning the repo.

I've tried git filter-branch, git-filter-repo and git rebase -i. They all create diverging histories.

答案1

得分: 2

由于Git的设计和操作原则,这简单不可能。具有不同历史记录的两个存储库不会在以后收敛到相同的提交哈希集。

英文:

It's simply not possible, due to the design and operating principles of Git. Two repos with different things in their history are not going to converge to the same set of commit hashes later on.

huangapple
  • 本文由 发表于 2023年6月18日 22:11:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76500971.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定