无法将代码提交到GitHub

3

我正在开发一个应用程序。我已经成功地将代码提交到GitHub几个月了。我到了需要将我的应用程序打包的时候。因此,它被打包成了一个ASAR文件。不幸的是,我没有将该文件添加到我的.gitignore文件中。现在,当我尝试检入代码时,我遇到了以下错误:

GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.        
Trace: [ID]        
See http://git.io/iEPt8g for more information.        
File App/MyApp.asar is 153.32 MB; this exceeds GitHub's file size limit of 100.00 MB

我了解问题。然而,我不想实际检查我的ASAR文件。所以,我将它添加到我的.gitignore文件中。然后我尝试将我的代码更改同步到GitHub,但是我仍然得到上面列出的错误。据我所知,我的代码更改已经提交到了我的本地分支。但是,由于上述文件已经尝试进行过检入操作,所以发生了一个记录阻塞的情况。
我不确定如何解除这个障碍。我需要那个提交中的代码更改,但是我不需要ASAR文件。我感到困惑,但是不知道该怎么解决。感谢任何帮助。
5个回答

2

好的,既然您已经提交了这个更改(因为您想将本地提交推送到Github),在推送到远程服务器之前,您需要撤销此更改,请查看此答案以了解如何执行此操作(git reset --soft HEAD~后跟更改(即删除此大文件)和新提交)。


1

在推送之前,您需要从历史记录中删除该文件。假设您添加文件的提交是abc123。执行git rebase -i abc123^。这将打开一个编辑器,列出该提交以及之后的所有提交。对于包含有关提交的行,请用“e”替换“pick”,然后关闭编辑器。Git将重放提交,然后停止。键入git rm --cached <filename>,然后键入git commit --amend。然后您应该能够推送。


0

正如您在错误消息中所看到的,Git 对文件大小有限制。

您需要从存储库中删除大文件。
您可以通过以下几种方式进行操作:


有许多不同的方法可以完全从git中删除文件的历史记录,以下是几个选项:

  • git rebase
  • 交互式变基。
  • 过滤分支。

git rebase

假设您有多个提交,而不仅仅是一个,则必须执行重新贴基操作。

# Checkout the commit where you commited the big file
git checkout -b <branch name> <SHA-1>

# Amend the commit
git rm <file>
git commit --amend --no-edit

# Rebase your previous branch onto this new commit, starting from the old-commit
git rebase --preserve-merges --onto <branch name> <old-commit> <original branch name>

交互式变基 (git rebase -i/-p)

enter image description here

交互式变基允许您以手动方式修改历史记录。 请记住,由于这是手动工作,因此在太多提交上进行操作会很困难。

// X is the number of commits you wish to modify
git rebase -i HEAD~X

一旦您打开编辑器

  • 选择s表示压缩 = 它将所有提交合并为一个提交。

  • 选择e以编辑所需的提交,git 将在此提交处停止重新基础,然后删除您的文件并再次提交它(git ammend 适用于任何给定的提交,仅适用于最后一个)。

例子:

# rebase has stopped at the given commit. edit it and remove our file
# same as you will do if it was the latest commit without using rebase
git rm <file>
git commit --amend --no-edit

# once the file removed - continue to the other commits if needed.
git rebase --continue

筛选分支

'git filter-branch'

git filter-branch --index-filter \
'git rm --cached --ignore-unmatch <file>'

这将在您选择的所有提交范围上执行给定的命令(在此代码片段中使用X删除不需要的文件以清理历史记录:

git filter-branch --index-filter \
'git rm --cached --ignore-unmatch <file>' HEAD~X..HEAD

bfg-repo-cleaner

不过bfg-repo-cleaner是一个比git filter-branch更快的解决方案。

enter image description here


-2
尝试使用以下命令从git索引中删除文件:
git rm FILEYOUWANTTOREMOVE

然后提交新的更改。 更多信息请参见:git-rm


-2

当你更改.gitignore文件时,不要忘记像这样清除缓存:

git rm --cached your_file

此外,如果您仍然遇到大文件的问题,建议您查看此链接:Git non-cached file being uploaded to Github

希望这可以帮助!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接