Git error resolution

        This article mainly summarizes the solutions to the problems encountered when using Git to submit and pull files, so that you can find them next time.

1 Solution to the problem of "git Failed to connect to 127.0.0.1 port xxxx: Connection refused" when using Git

1. Problem description

        When using git to pull and submit code, the problem git Failed to connect to 127.0.0.1 port xxxx: Connection refused will occur.

        Reason: Unable to connect to 127.0.0.1: xxx port: Connection refused.

2. Solution
Option 1:
        Idea: Check whether there is an agent currently, and cancel if there is.

// 首先,查一下当前全局的 http 代理:
git config --global http.proxy
// 如果有代理,就取消
git config --global --unset http.proxy


// 再查 https 的代理:
git config --global https.proxy
// 同样的,有就取消
git config --global --unset https.proxy

Option II

        If the above solution does not work, please refer to this solution

// 首先,查一下代理:
env|grep -i proxy
// 有就取消
unset http_proxy
unset https_proxy

// 再查
env|grep -i proxy
// 正常情况下是没有代理了
// 再次查询一下,如果还有的再取消

third solution

  • Modify environment variables
  • Variableshttp_proxy and https_proxy were found in the system variables. You can also check whether there are user variables and delete them.
  • Restart the computer.
  • Use git again, it's normal, check againenv|grep -i proxy, the agent is gone.

3. Summary

        With the agent gone, you can pull and submit code normally.

This part is referenced from:About the solution to the problem of "git Failed to connect to 127.0.0.1 port xxxx: Connection refused" when using Git

2 error: src refspec master does not match any

1. Problem description

        When uploading a local project to the newly created warehouse, the following error occurred:

        The content of the question is:

  • Error: SRC ReFSPEC master does not match any.
  • Error: failed to push some references to[email protected]:molimi/MyBlog.git

2. Solution

        ​​​​​In fact, you only need to perform the following steps to upload local projects to Github

  1. Create a local repository (i.e. folder) and turn it into a Git repository through git init;
  2. Copy the project to this folder, and then add the project to the warehouse through git add.
  3. Then submit the project to the warehouse through git commit -m "注释内容";
  4. After setting up the SSH key on Github, create a new remote warehouse and associate the local warehouse with the remote warehouse through git remote add origin https://github.com/molimi/MyBlog.git;
  5. Finally push the project of the local warehouse to the remote warehouse (that is, Github) throughgit push -u origin master; (If a README file is automatically created when creating a new remote warehouse, an error will be reported. See the solution. above).

This section is referenced from:error: src refspec master does not match any. Error solution

3 fatal: unable to access ‘https://XXX/’: OpenSSL SSL_read: Connection was reset, errno 10054

1. Problem description

        The previously associated github library cannot be uploaded (push), and it prompts that the local library does not exist. So I did it

git init  # 初始化资源库
git remote-v origin https://http://github.com/我的库  # 将本地库与远程库做关联,
git pull      # 先将线上的资源拉取下来。

        The problem lies in the git pull prompt.

fatal: unable to access 'http://github.com/我的库/': OpenSSL SSL_read: Connection was reset, errno 10054

        Reason for error:

  • Literal meaning: The server's SSL certificate has not been signed by a third-party organization.
  • Some online information also says that it may be caused by unstable network and connection timeout.

2. Solution
        Modify the settings and cancel SSL verification. Open the command line tool and enter:

git config --global http.sslVerify "false"
git config --global https.sslVerify "false"

        The real reason is that the DNS is contaminated, and the github.com pinged in China may have been tampered with. Just modify the hosts yourself and add the correct IP of github.

4 remote: error: File:1f6cc8452313 157.10 MB, exceeds 100.00 MB

1. Problem description

        According to the reasons for the error, the gitee free user single file is the maximum 100M, so it can only be uploaded to less than 100M files

(1) View large file names

$ git rev-list --objects --all | grep 9fc69e9816e94fb5bde1f86b31581d7ec12ede3b
9fc69e9816e94fb5bde1f86b31581d7ec12ede3b 2023/项目实战/NotPush/pytorch_resnet50.pth

        It turned out that the file 2023/项目实战/NotPush/pytorch_resnet50.pth was larger than 100M.

        Of course, you can also execute the following code: to find out the largest file submitted in history.

$ git rev-list --objects --all | grep "$(git verify-pack -v .git/objects/pack/*.idx | sort -k 3 -n | tail -5 | awk '{print$1}')"

2. Solution

(1) Delete the file in submission

git filter-branch --force --index-filter  "git rm --cached --ignore-unmatch 2023\\项目实战\\NotPush\\pytorch_resnet50.pth"  --prune-empty --tag-name-filter cat -- --all
  • If the code is changed, an error message is reported: Cannot rewrite branches: You have unstaged changes
  • Solution: First execute:git stash, then execute the command again.

(2) Resubmit

        To push your repo with forced coverage, the command is as follows:

git push origin master --force

(3) Clean up and reclaim space

        Although we have deleted the files above, these objects are still retained in our repo, waiting for garbage collection (GC), so we need to use the command to completely clear it and reclaim the space. The command is as follows:

rm -rf .git/refs/original/
 
git reflog expire --expire=now --all
 
git gc --prune=now      # 执行命令 清楚本地缓存刷新

Guess you like

Origin blog.csdn.net/xq151750111/article/details/133979844