全网多种方法解决Updates were rejected because the remote contains work that you do not have locally的错误

这篇具有很好参考价值的文章主要介绍了全网多种方法解决Updates were rejected because the remote contains work that you do not have locally的错误。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

1. 复现错误


今天使用git status查看文件状态,发现有一个文件未提交,如下代码所示:

D:\project\test>git status
On branch master
Your branch is up to date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/main/java/xxx/po/test.java

nothing added to commit but untracked files present (use "git add" to track)

既然未提交,则首先使用git add将当前目录下修改的代码,从工作区添加到暂存区,如下代码所示:

D:\project\test>git add  src/main/java/xxx/po/test.java

接着使用git commit将缓存区内容添加到本地仓库,如下代码所示:

D:\project\test>git commit -m "test"
[master 0b983e7] test
 1 file changed, 9 insertions(+)
 create mode 100644 src/main/test/po/test.java

但使用git push origin master将本地版本库推送到远程服务器时,却报出如下错误:

D:\project\test>git push
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
To https:xxx/test.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https:xxx/test.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

updates were rejected because the remote contains work that you do,免费专栏,git,github,运维,后端,java

Updates were rejected because the remote contains work that you do not have locally

2. 分析错误


Updates were rejected because the remote contains work that you do not have locally翻译成中文就是更新被拒绝,因为远程包含您本地没有的工作

换句话说,我们想把自己本地的某个项目,关联到远程仓库并推送上去,但为什么报这个错误呢?

原来,我们在创建仓库时,都会勾选使用Reamdme文件初始化这个仓库这个操作,初始了一个README文件,并配置添加了忽略文件:
updates were rejected because the remote contains work that you do,免费专栏,git,github,运维,后端,java

当点击创建仓库时,它会帮我们做一次初始提交。

于是,我们的仓库就有了README.m.gitignore文件。

接着,我们把本地项目关联到这个仓库,并把项目推送到仓库时。

我们在关联本地与远程时,两端都是有内容的,但这两份内容并没有联系。

当我们推送到远程或者从远程拉取内容时,都会存在没有被跟踪的内容。

于是,你看git报的详细错误中,总是会让你先拉取再推送,如下图所示:

updates were rejected because the remote contains work that you do,免费专栏,git,github,运维,后端,java

3. 解决错误


既然需要先拉取,再推送,便可以使用如下解决方法。

  1. 首先,使用git pull --rebase origin master命令拉取,如下代码所示:
D:\project\test>git pull --rebase origin master

warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
remote: Counting objects: 33, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 33 (delta 5), reused 0 (delta 0)
Unpacking objects: 100% (33/33), 23.26 KiB | 58.00 KiB/s, done.
From https:xxx/test
 * branch            master     -> FETCH_HEAD
   453fc37..97defce  master     -> origin/master
Successfully rebased and updated refs/heads/master.


  1. 接着,使用git push -u origin master命令上传代码,如下代码所示:
D:\project\test>git push -u origin master

warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
warning: ----------------- SECURITY WARNING ----------------
warning: | TLS certificate verification has been disabled! |
warning: ---------------------------------------------------
warning: HTTPS connections may not be secure. See https://aka.ms/gcmcore-tlsverify for more information.
Enumerating objects: 22, done.
Counting objects: 100% (22/22), done.
Delta compression using up to 12 threads
Compressing objects: 100% (8/8), done.
Writing objects: 100% (12/12), 898 bytes | 898.00 KiB/s, done.
Total 12 (delta 3), reused 0 (delta 0), pack-reused 0
To https:xxx/test.git
   97defce..c60a6e6  master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.

如此,便可以推送成功。

如果这种解决方法无法解决你的错误,可以参考如下解决方法。

4. 解决该错误的其他方法


想要避免这种问题,就要保持创建的仓库是一个空仓库,什么都没有。

也就是在创建仓库时,不要勾选使用Readme文件初始化这个仓库,如下图所示:

updates were rejected because the remote contains work that you do,免费专栏,git,github,运维,后端,java

然后,克隆下来使用,下次要推送,即可直接推送。

如果这两种方法都无法解决你的错误,烦请在评论区留言。文章来源地址https://www.toymoban.com/news/detail-779094.html

到了这里,关于全网多种方法解决Updates were rejected because the remote contains work that you do not have locally的错误的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • git报错:Updates were rejected because the tip of your current branch is behind

    多人协作项目,其他成员提交之后,你这边没有拉取最近代码就要进行推送,远程仓库和本地仓库不同步。 一般远程仓库和本地仓库是同步的,当有另一个人克隆远程仓库并修改推送代码后,你这边的本地仓库再进行推送会提示这个错误。“更新被拒绝,因为您当前分支的提

    2024年02月15日
    浏览(63)
  • 【Github】hint: Updates were rejected because the remote contains work that you do && remote: error: G

    Q: git push 报错 翻译 A:这是因为在上传的时候,远程仓库中有着本地仓库没有的文件(与远程仓库的内容不一致),即导致本地仓库和远程有不同的开始点,也就是两个仓库没有共同的 commit ,所以无法提交,解决方法如下: 参考教程https://www.cnblogs.com/yanhuidj/p/9301328.html 正确的

    2024年02月03日
    浏览(41)
  • 从git提交出现“updates were rejected because a pushed branch tip is behind its remote”到提交成功解决问题的过程

    这里是不断发芽的山有木兮,希望这个帖子可以帮到你! git提交出现“updates were rejected because a pushed branch tip is behind its remote” git报错如下:

    2024年02月02日
    浏览(49)
  • git 提交出现 Updates were rejected 解决方案记录

    git remote add 添加一个远程地址 但提交出现以下报错 VBNET 复制 全屏 解决 也就是说,如果您确定处于分离状态的master版本是您真正想要保留的版本,那么您可以通过强制将分支推送到远程来避免非快进错误: git push origin HEAD:master --force 但是,如果强制推送,则可能会给签出该

    2024年02月07日
    浏览(44)
  • 全网多种方法解决You have an error in your SQL syntax; check the manual that corresponds to your MySQL server

    今天在调试低代码的接口,突然报出如下的错误: 即 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near \\\'desc,name,is_deleted ) VALUES(\\\'测试哈\\\',\\\'测试哈\\\',\\\'测试项目\\\',1 )\\\' at line 11 。 于是,查看控制台报出的详细错误信息,如下图所示

    2024年02月15日
    浏览(55)
  • FileUploadException: the request was rejected because no multipart boundary was found

    前端使用 form 提交文件到后端。 使用 jquery/axios/fetch 或其他HTTP客户端程序发送HTTP请求,但是后端(Spring框架)报错如下: 我是因为设置了 \\\"Content-Type\\\": \\\"multipart/form-data\\\" 这样的头,才会失败。 这个请求头的格式样例(见https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type):

    2024年02月10日
    浏览(56)
  • fileupload.FileUploadException: the request was rejected because no multipart boundary was found

    前端小程序调用服务端的文件上传接口,有一台安卓机上传一直报错: 报错日志: {\\\"statusCode\\\": 500, \\\"header\\\": {\\\"Date\\\": \\\"Wed, 29 Mar 2023 06:45:39 GMT\\\", \\\"Content-Language\\\": \\\"en\\\", \\\"Server\\\": \\\"nginx\\\", \\\"Content-Type\\\": \\\"text/html;charset=utf-8\\\", \\\"Transfer-Encoding\\\": \\\"chunked\\\", \\\"Connection\\\": \\\"keep-alive\\\", \\\"protocol\\\": \\\"http/1.1\\\"}, \\\"data

    2024年02月03日
    浏览(69)
  • Multiple HTTP implementations were found on the classpath错误的解决方法

    当我们的项目中集成了多个AWS相关Jar包时,有可能就会遇到这个错误: 错误信息: There is an issue with the connector Code: InvalidInput.InvalidConnectorConfiguration Message: The connector configuration is invalid. Message: Multiple HTTP implementations were found on the classpath. To avoid non-deterministic loading implementation

    2024年02月11日
    浏览(45)
  • 全网多种方法解决error: failed to push some refs to ‘xxx‘

    今天使用 git status 查看文件状态,发现有一个文件未提交,如下代码所示: 既然未提交,则首先使用 git add 将当前目录下修改的代码,从工作区添加到暂存区,如下代码所示: 接着使用 git commit 将缓存区内容添加到本地仓库,如下代码所示: 但使用 git push origin master 将本地

    2024年02月16日
    浏览(49)
  • 全网多种方法解决Invalid Host header(无效的主机头)服务器域名访问出现的错误

    在搭建 vue-cli 环境,用 nginx 做代理服务器,访问时却显示: Invalid Host header 。 知其然,知其所以然,我们在解决该问题之前,要弄明白 Invalid Host header 是什么。 ChatGPT 目前正火,可以借助 ChatGPT 来回答, Invalid Host header 是什么,如下图所示: The “Invalid Host header” error typ

    2024年02月03日
    浏览(38)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包