如何在IntelliJ/Git中合并两个独立的提交,以使一个文件完全被删除?

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

How do I merge two separate commits so that a file is completely removed in IntelliJ/Git?

问题

在我的项目中,我有一个文件超过 100 MB(这意味着我无法将其上传到 Github)。我提交了我的更改,包括添加了该文件。然后我意识到这个文件是不必要的,于是我将其删除。然而,当我再次提交时,由于那个被删除的文件超过了 100 MB 的限制,我仍然无法推送我的提交,即使我在随后的提交中将其删除。有没有办法合并这两个提交,使得这个文件从未存在,从而不尝试将其推送到 Github?

我知道我可以使用类似 git-lfs 的东西,但我只是想知道是否有一种更快速的方法来解决这种问题。

英文:

In my project, I had one file which is over 100 MB (which means I am unable to upload it to Github). I committed my changes, including the addition of the file. I then realized that the file was unneeded, and I removed it. However, when I committed again, I was still unable to push my commits because of that one file which was removed being over the 100 MB limit, even though I removed it in the subsequent commit. Is there a way to merge these two commits so that the file never existed so that it doesn't try to push it to Github?

I know I can use something like git-lfs, but I was just curious to see if there was a faster way to fix this kind of problem.

答案1

得分: 1

你可以从一个没有那个100MB文件的提交开始使用 git rebase -i,然后编辑那些错误地将这个文件添加到你的历史记录中的提交。

英文:

You can use git rebase -i starting from a commit which doesn't have the 100MB file, and edit the commits that wrongly add this file in your history.

huangapple
  • 本文由 发表于 2023年5月17日 13:29:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/76268814.html
匿名

发表评论

匿名网友

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

确定