You may want to first integrate the remote changes (e.g., ‘git pull ...‘) before pushing again多种解决方法
文章目录
- 1. 复现错误
- 2. 分析错误
- 3. 解决错误
- 4. 解决该错误的其他方法
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.javanothing 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] test1 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.
即This is usually caused by another repository pushing to the same ref.
。
2. 分析错误
You may want to first integrate the remote changes (e.g., 'git pull ...') before pushing again.
翻译成中文就是您可能希望首先集成远程更改(例如,“git pull ...”),然后再推送
。
换句话说,我们想把自己本地的某个项目,关联到远程仓库并推送上去,但为什么报这个错误呢?
原来,我们在创建仓库时,都会勾选使用Reamdme文件初始化这个仓库
这个操作,初始了一个README
文件,并配置添加了忽略文件:
当点击创建仓库时,它会帮我们做一次初始提交。
于是,我们的仓库就有了README.m
和.gitignore
文件。
接着,我们把本地项目关联到这个仓库,并把项目推送到仓库时。
我们在关联本地与远程时,两端都是有内容的,但这两份内容并没有联系。
当我们推送到远程或者从远程拉取内容时,都会存在没有被跟踪的内容。
于是,你看git
报的详细错误中,总是会让你先拉取再推送,正如上文提到的错误,如下图所示:
3. 解决错误
既然需要先拉取,再推送,便可以使用如下解决方法。
- 首先,使用
git pull --rebase origin master
命令拉取,如下代码所示:
D:\project\test>git pull --rebase origin masterwarning: ----------------- 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_HEAD453fc37..97defce master -> origin/master
Successfully rebased and updated refs/heads/master.
- 接着,使用
git push -u origin master
命令上传代码,如下代码所示:
D:\project\test>git push -u origin masterwarning: ----------------- 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.git97defce..c60a6e6 master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
如此,便可以推送成功。
如果这种解决方法无法解决你的错误,可以参考如下解决方法。
4. 解决该错误的其他方法
想要避免这种问题,就要保持创建的仓库是一个空仓库,什么都没有。
也就是在创建仓库时,不要勾选使用Readme文件初始化这个仓库
,如下图所示:
然后,克隆下来使用,下次要推送,即可直接推送。
如果这两种方法都无法解决你的错误,烦请在评论区留言。
You may want to first integrate the remote changes (e.g., ‘git pull ...‘) before pushing again多种解决方法相关推荐
- 【Git】Git commit至Gitee报错‘remote: error: hook declined to update refs/heads/master‘的解决方法
Git commit至Gitee报错'remote: error: hook declined to update refs/heads/master'的解决方法 进入到Gitee的邮箱管理中,取消勾 ...
- Git commit至Gitee报错‘remote: error: hook declined to update refs/heads/master‘的解决方法
进入到Gitee的邮箱管理中,取消勾选禁止命令行推送暴露个人邮箱
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决方法
WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决方法 参考文章: (1)WARNING: REMOTE HOST IDENTIFICATION HAS ...
- ssh_exchange_identification: Connection closed by remote host 解决方法
ssh_exchange_identification: Connection closed by remote host 解决方法 参考文章: (1)ssh_exchange_identificat ...
- linux下,每次git pull 或者git push都需要输入账号密码的问题以及git remote 的一些基本操作
一.背景 这个问题以前并没有出现过,最近才出现.对比了下,发现以前连接远程仓库用的是git remote加远程仓库url 连接的.而这次试用git clone直接下载的码云上面的,所以才会出现这种差异 ...
- git使用报错:fatal: Couldn't find remote ref master的解决方法
git使用报错:fatal: Couldn't find remote ref master的解决方法 fatal: Couldn't find remote ref master 翻译过来就是:致命 ...
- 解决git push 中remote: Permission to xxxxx.git denied to xxx. fatal: unable to access xxxx 403(转)
问题复现 你在切换多个github账号的时候,很容易出现下面的这种问题 问题描述 今天我在使用git push 将修改的项目push到github中,出现: remote: Permission to ...
- Weblogic - Failed to bind remote object 错误解决方法
环境 Solaris 10 Enterprise Weblogic 9.2.1.0 一.错误解决 今天上午,QA测试一同事的应用时,在建立JDBC连接池并绑定到JNDI时出错,弄了许久,同事和QA都没 ...
- git init、git status、git config user.name、git add、git commit、git remote、git push、git clone、git pull
1. Git本地仓库初始化 1.1 git init 功能 git init:初始化一个新本地仓库,它会在工作目录下生成一个.git的隐藏文件夹来管理仓库,千万不要删掉它. 1.2 git statu ...
最新文章
- 2021年大数据Flink(五):Standalone-HA高可用集群模式
- postgresql select for update 多行加锁顺序_insert into select加锁规则补充
- 少女时代成为主流:这是一件好事吗?
- OpenMP的一点使用经验
- 数据库的内连接和外连接区别?
- php面向对象分页,PHP基于面向对象封装的分页类示例
- R语言:异常数据处理
- 如何向Spring Bean 中注入java.util.Properties?
- java解析java源码_JAVA语言-Java源码解析-Stack源码分析
- 学习template算法以及改进(一)
- 加载不了ajax,简单的jquery ajax内容加载不起作用
- 斯诺登:澳大利亚的监视政策比NSA还下流
- linux shell编程大作业,《Linux操作系统》Shell编程大作业-01-潘春艳.doc
- 【Python 数据科学】分组group by基础
- Java 证书 数字签名_JAVA 给PDF添加数字签名
- 用u盘重装微软官方win10专业版--详细操作文档
- 欧几里得算法及其扩展欧几里得算法——数论
- EtherCAT从设备输入输出实现
- 树立产学研合作典范,IBM携手十所商学院共同打造百企大数据合作计划A100升级版...
- 2021【敏捷CSM认证】Sprint回顾会议-检视工作,提升效率