如何从初始提交中删除目录:推入github失败
我想在github上放置我的遗产代码。以愚蠢的举动,我选择了整个项目(以pycharm)添加到初始提交中。我忘记了这包括巨大且超过任何文件和回购大小限制(8+ GB)的数据和绘图目录。我曾经希望我以后只能删除不必要的文件和目录,但是:
最初推向GitHub失败了,我似乎无法使用git git revert
,git git reset 和我在这里找到的其他方法,因为以前没有提交返回的提议。
我不想冒我的代码风险,所以我转向您:如何
- 从commit 中删除有问题的目录和其中的文件,但不是我的磁盘 ,还是
- 抛弃此(本地)存储库,然后将一个新的存储库连接到Github,在我不包括这些目录中的Github?
我在这里浏览了很多答案,但我似乎找不到一个答案。这很明显吗?谢谢大家的帮助! :)
I want to put a legacy code of mine on GitHub. In a foolish move, I selected the whole project (in PyCharm) to add to the initial commit; I forgot that this includes data and plot directories that are huge and exceed any file and repo size limit (8+ GB). I had hoped I could just remove the unnecessary files and directories later on, but:
The initial push to GitHub fails, and I seem to not be able to use git revert
, git reset
and other methods I found here, since there is no previous commit to go back to.
I don't want to risk my code, so I turn to you: how to I either
- remove the offending directories and the files therein from the commit but not from my disk, or
- ditch this (local) repository and make a new one to connect to GitHub, where I do not include these directories from the get-go?
I looked through many, many answers here, and I just don't seem to find one. Is it that obvious? Thank you all for your help! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
假设您只有一个提交(“初始提交”):
这只能从提交中删除文件,但将其留在文件系统上。
如果您在初始提交的基础上已经有不同的提交,请创建一个fixup commit以删除这些文件,然后进行交互作用:
我不能100%确定rebasing是否可以意外删除这些文件。为了安全起见,请先创建文件备份或将其移至其他目录。 (如果它们是从FS中消失的,则它们仍应以斑点对象存在于对象存储中,但是恢复它们将需要一些工作)。
Assuming you only have a single commit ("the initial commit"):
This will remove the files only from the commit, but leave them on the file system.
If you already have different commits on top of your initial commit, create a fixup commit removing those files and then rebase interactively:
I'm not 100% sure if rebasing could remove those files accidentally. To be on the safe side, create a backup of the files first or move them to a different directory. (If they are gone from the FS they should still exist in the object store as blob objects, but restoring them will require some work).