git push试图推送未列在git ls-files中的文件 [英] git push trying to push files not listed in git ls-files

查看:151
本文介绍了git push试图推送未列在git ls-files中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意外地在我的回购库中提交了一个不必要的大型子文件夹xxxxx,当我在推送过程中意识到这一点时,我中途停止了推送。

然后我删除了一个不必要的使用

  git rm -r --cached xxxxx 

但是当 ls-files 不显示xxxxx文件夹时,git仍然在尝试推送它我做了 git push

  git push --verbose 
(...)

计数对象:19,完成。
使用多达8个线程的增量压缩。
压缩对象:100%(18/18),完成。
POST git-receive-pack(分块)
写作对象:100%(19/19),132.93 MiB | 197.00 KiB / s,完成。
总计19(增量5),重用0(增量0)
远程:警告:文件xxxxx / a.csv是72.22 MB;这大于GitHub Enterprise建议的最大文件大小为50.00 MB
remote:错误:GH001:检测到大文件。
remote:错误:文件xxxxx / b是112.37 MB;这超过了GitHub Enterprise的文件大小限制为100.00 MB

如何让git永久地忘记xxxxx文件夹和它的内容?

解决方案

git push ,它会推送提交。具体来说,它会推动你没有的提交(无论他们是谁 - 你推送的远程)。他们抱怨说,至少有一个提交包含至少一个大文件。



您需要推送一些不同的提交,以便您提交的提交不包含大文件。



通常,执行此操作的方法是将每个良好提交完好无损,将其复制到新分支,对于每个坏提交,提取好的部分,删除不好的部分,并从结果中做出新的提交。例如,假设这是远程提交的提交图:

  A < -  B < -  C < -  D < -  origin / master 

假设您已经添加了三个提交,但是存在一个问题中间一个:

  A  -  B  -  C  -  D < -  origin / master 
\
E - F - G < - master

当您运行 git push 您的git发送了提交 E F G 和远程抱怨,因为 F 具有不应该有的文件。为了解决这个问题,你可以简单地将 E 复制到一个新的分支中,我们称之为副本 E' - 然后复制 - 修复 F 以使 F',然后复制 G 使 G'。我们还要重命名旧的(坏) master ;实际上,让我们完全删除这个名字,以便我们有这个:

  E' -  F' -  G'< ;  - 主
/
A - B - C - D < - 原产地/主产地
\
E - F - G [弃用]

执行此复制的git命令是 git rebase 。通常它只是直接复制;您希望它复制 E ,但是随后停止并让您修复 F ,然后复制 G ,要做到这一点的方法是使用 -i - interactive flag。



一般而言,您应该只更改只提供 的提交,但幸运的是,正好是 git push 应该推送的集合,无论你推什么分支, origin / branch (或任何远程名称,如果它不是 origin )将界定远程提交(和其他人拥有)。



交互式重新分配可以做得比这更多,所以请参阅 Git Book 获取说明。这也取决于你确定哪些提交包含哪些大文件;为此, git show git diff 是有用的工具。


I accidentally committed an unnecessary large subfolder xxxxx in my repo, and when I realized this while pushing, I stopped the push midway through.

Then I removed an unnecessary folder xxxxx from the repo using

git rm -r --cached xxxxx

But while ls-files does not show the xxxxx folder, git is still trying to push it when I do git push:

git push --verbose
(...)

Counting objects: 19, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (18/18), done.
POST git-receive-pack (chunked) 
Writing objects: 100% (19/19), 132.93 MiB | 197.00 KiB/s, done.
Total 19 (delta 5), reused 0 (delta 0)
remote: warning: File xxxxx/a.csv is 72.22 MB; this is larger than GitHub Enterprise's recommended maximum file size of 50.00 MB
remote: error: GH001: Large files detected.
remote: error: File xxxxx/b is 112.37 MB; this exceeds GitHub Enterprise's file size limit of 100.00 MB

How make git permanently forget about "xxxxx" folder and its contents?

解决方案

git push does not push files, it pushes commits. Specifically, it pushes commits that you have that they don't (whoever "they" are—the remote to which you are pushing). They are complaining that at least one of your commits contains at least one large file.

You'll need to push some different commits, so that the commits you're pushing don't contain the large file.

As a general rule, the way to do this is to take each "good" commit intact, copying it to a new branch, and for each "bad" commit, extract the good parts, remove the bad parts, and make a new commit out of the result. For instance, suppose this is a drawing of the commits the remote has:

A <- B <- C <- D    <-- origin/master

Suppose you've added three commits but there's a problem in the middle one:

A - B - C - D       <-- origin/master
             \
              E - F - G   <-- master

When you run git push your git sends commits E, F, and G, and the remote complains because F has file(s) it should not. To fix this you can simply copy E to a new branch—we'll call the copy E'—then copy-but-fix F to make F', then copy G to make G'. Let's also rename the old ("bad") master; in fact, let's just drop the name entirely, so that we have this instead:

              E' - F' - G'   <-- master
             /
A - B - C - D       <-- origin/master
             \
              E - F - G      [abandoned]

The git command that does this copying is git rebase. Normally it just copies straight through; you want it instead to copy E, but then stop and let you fix F, and then copy G, and the way to get it to do that is to use the -i or --interactive flag.

In general, you should only copy-while-changing commits that only you have, but fortunately this is exactly the set that git push should be pushing, and whatever branch you're pushing, origin/branch (or whatever the remote name is, if it's not origin) will delimit the commits that the remote has (and other people have).

Interactive rebase can do a lot more than this, so see the Git Book for instructions. It's also up to you to figure out which of your commit(s) contain which large file(s); for this, git show and git diff are helpful tools.

这篇关于git push试图推送未列在git ls-files中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆