Git 在写入对象时挂起

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6887228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:27:21  来源:igfitidea点击:

Git hangs while writing objects

git

提问by mattalxndr

I'm trying to git push -u origin masterAnd it just hangs at

我正在尝试git push -u origin master它只是挂在

Writing objects:  99% (219/220), 12.65 MiB | 97 KiB/s

The 12.65part shifts around. When I exit the process and run it again, it resumes at 99% but never finishes, same as before.

12.65部分转移四周。当我退出进程并再次运行它时,它以 99% 恢复但从未完成,与以前一样。

It's never pushed successfully. This is the initial commit.

它从未成功推送。这是最初的提交。

采纳答案by mattalxndr

This was happening because of huge, unignored file in the repo directory. Whoops.

这是因为 repo 目录中存在巨大的、未被忽略的文件。哎呀。

EDIT

编辑

The hang was because the file was taking a long time to upload. The file wasn't supposed to have been included in the push.

挂起是因为文件需要很长时间才能上传。该文件不应该包含在推送中。

EDIT

编辑

While it's true that a huge file could be the reason behind this issue, if you can't ignore the file in question or just haveto push it then follow thisanswer.

虽然这个问题背后的原因确实是一个巨大的文件,但如果您不能忽略有问题的文件或只需要推送它,那么请遵循这个答案。

回答by Hugo Forte

I followed VonC's advice:

我听从了 VonC 的建议:

git config --global http.postBuffer 524288000


For future references, based on comments:

供以后参考,基于评论:

500 MB: 524288000 (as posted in the original answer)
1 GB: 1048576000
2 GB: 2097152000 (anything higher is rejected as 'out of range')

回答by Maha

I had the same problem with (writing objects %16) stuck then fatal. I solved this by saving the current changes and clone a new repository, then copy the modified files into it.

我有同样的问题(写入对象 %16)卡住然后致命。我通过保存当前更改并克隆一个新存储库来解决此问题,然后将修改后的文件复制到其中。

Eg. Assume current repository is A, then all you need to do is:

例如。假设当前存储库是 A,那么您需要做的就是:

  1. mv A B
  2. git clone A
  3. mv B/* A/
  4. rm -rf B
  1. mv A B
  2. git clone A
  3. mv B/* A/
  4. rm -rf B

Then commit and push and it all worked fine. It recognized the moved files as modified :)

然后提交并推送,一切正常。它将移动的文件识别为已修改:)

回答by Naewis

In my case, I was using a git folder with bad rights stored on the same drive as a repo, but it could be the same with ssh even if you use an authorized login user.

就我而言,我使用的 git 文件夹与存储在存储库相同的驱动器上具有错误的权限,但即使您使用授权登录用户,它也可能与 ssh 相同。

Check then if you have correct rights to write on the distant repo.

然后检查您是否具有在远程存储库上写入的正确权限。

Example:

例子:

Init local and distant repo

初始化本地和远程仓库

git init /tmp/src
git init --bare /tmp/dst
cd /tmp/src

Adding remote repo to origin

将远程仓库添加到源

src > git remote add dest /tmp/dst

Simulating problem

模拟问题

src > chmod -R 555 /tmp/dst

Adding fake file and pushing it

添加假文件并推送

src > touch a && git add a && git commit -m 'demo'
src > git push --set-upstream dest master
src > git push
Counting objects: 3, done.
Writing objects: 99% (2/3), 202 bytes | 0 bytes/s.

Git hangs

Git挂起

Solution

解决方案

src > chmod -R 775 /tmp/dst

回答by user3160702

In my case I was having slow internet upload speed and the file I wanted to push was big, the trick is to use git LFS (large file storage) that is much more patient to upload big files, you can find a git LFS tutorial here

在我的情况下,我的互联网上传速度很慢,我想推送的文件很大,诀窍是使用 git LFS(大文件存储),它更耐心地上传大文件,你可以在这里找到git LFS 教程

回答by Skitty

In my situation it was the size of the file. By adding an .gitignore file with the required extensions I was able to ignore most of the unwanted files to be pushed.

在我的情况下,它是文件的大小。通过添加具有所需扩展名的 .gitignore 文件,我能够忽略大部分不需要的文件。

回答by Onat Korucu

In my case, I was trying to push without completing my company's rules. I learnt later that we should start our commit messages with "MOBIL-XXXX" where XXXX is the number developers are assigned in Jira (another tool we use to track development process) by analists.

就我而言,我试图在没有完成公司规则的情况下推动。后来我了解到,我们应该以“MOBIL-XXXX”开始我们的提交消息,其中 XXXX 是分析师在 Jira(我们用来跟踪开发过程的另一个工具)中分配给开发人员的编号。

Make sure to check if your company has a similar constraining rule.

请务必检查您的公司是否有类似的限制规则。

回答by Sherlock

git clean -f -nsolves my issue. There are many untracked files not detected. But be careful because this will remove files in your directory

git clean -f -n解决了我的问题。有许多未跟踪的文件未检测到。但要小心,因为这会删除您目录中的文件