1.报错信息
当我们在IDEA中点击push按钮要将本地版本仓库推送到远程版本仓库gitee时候,常会出现以下报错信息:This is usually caused by another repository pushing to the same ref.
将该报错信息翻译为中文为:这是由于另一个存储库推送到同一引用而引起的。
2.分析报错
当我们在gitee或者github创建仓库时,不小心勾选了初始化该仓库的单选框,初始化仓库时,仓库内会自动创建README.m和.gitignore文件,系统会将这一举动作为第一次初始提交。然而当我们将本地版本仓库推送到远程版本仓库gitee时候,两端都是有内容的,而且这两端的内容没有联系,因此当我们对远程仓库进行操作(推送或拉取)时,均会存在没有被跟踪的文件内容。而报错中也提示说要先拉取,再推送,从而使两者建立联系。
3.解决报错
首先我们可以在该项目目录中,使用git pull --rebase origin master命令来拉取:
PS D:\Java\IDEA\workspace\shixun\ErrorTest> git pull --rebase origin master
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 1.87 KiB | 147.00 KiB/s, done.
From https://gitee.com/fxw0817/error-test
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
Successfully rebased and updated refs/heads/master.
然后使用git push -u origin master命令上传代码
PS D:\Java\IDEA\workspace\shixun\ErrorTest> git push -u origin master
Enumerating objects: 27, done.
Counting objects: 100% (27/27), done.
Delta compression using up to 12 threads
Compressing objects: 100% (16/16), done.
Writing objects: 100% (26/26), 3.12 KiB | 3.12 MiB/s, done.
Total 26 (delta 3), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [1.1.5]
remote: Set trace flag ea4a26a6
To https://gitee.com/fxw0817/error-test
f9985d3..8d84590 master -> master
branch 'master' set up to track 'origin/master'.
接下来代码就可以推送成功了。