🎯🎯🎯问题描述:
命令中的duzhongbo就是我远程地址的别名,也就是下面这条命令起到的效果
git remote add duzhongbo https://github.com/WuPeiqi/pondo.git
当然后面这个地址并不是我的,举个例子
报错的错误:
error: failed to push some refs to 'gitee.com:du-zhongbo202024/epositoryp.git'
hint: Updates were rejected because the remote contains work that you do not
hint: have locally. This is usually caused by another repository pushing to
hint: the same ref. If you want to integrate the remote changes, use
hint: 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
这个问题是将本地的 master 分支推送到远程 Gitee 仓库时,远程仓库已经有了你本地仓库所没有的提交
看到的解决办法是将远程仓库中的内容直接拉到工作区中就好了,于是我试了:
$ git pull duzhongbo1 master
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (4/4), 1.82 KiB | 372.00 KiB/s, done.
From https://gitee.com/du-zhongbo2020260724/program_tool_repositoryp
* branch master -> FETCH_HEAD
* [new branch] master -> duzhongbo1/master
fatal: refusing to merge unrelated histories
还是不行,下面是另外成功的操作,供参考:
首先为了解决地址别名气的太多的情况,先把全部别名清空咱重新来一遍,不行你过来打死我😁😁😁
开始🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹🌹
- 首先查询一下所有为远程地址起过别名
git remote -v
- 全部删掉,重新开始
git remote remove 别名
直到再次使用git remote -v 查询是不显示任何内容为止!
3. 重新开始,拷贝下仓库的ssh
使用下面语句为仓库的远程地址取别名:
git remote add origin git@gitee.com:du-zhongbo2020260724/program_tool_repositoryp.git
- 查询一下是否成功
git remote -v
origin git@gitee.com:du-zhongbo2020260724/program_toryp.git (fetch)
origin git@gitee.com:du-zhongbo2020260724/prepositoryp.git (push)
显示上面信息就是成功,有两个url是没错的。
在Git中,每个远程仓库都有两个URL关联,一个是fetch URL,另一个是push URL。这两个URL在git remote -v命令的输出中体现,分别用于不同的操作:
fetch URL: 这个URL是当你执行git fetch、git pull等命令时,Git用来从远程仓库获取数据的地址。当你需要从远程仓库获取最新的提交、分支或者其他资源时,Git会连接到这个地址。
push URL: 这个URL则是当你执行git push命令时,Git用来将本地提交推送到远程仓库的地址。当你想要分享本地的改动到远程仓库,使其他人能访问到你的更新时,Git会使用这个地址。
通常情况下,fetch和push URL是相同的,除非为同一个远程仓库设置了不同的fetch和push地址。这样做的好处是可以针对拉取和推送分别配置不同的访问策略,比如不同的访问凭据或者不同的访问路径。
- 将本地内容push上去
这个时候用git push origin master将版本库中master分支上的内容推到远程地址别名为origin的地址时还是报了一下问题:
error: failed to push some refs to 'gitee.com:du-zhongbo2020260724/program_tool_repositoryp.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. If you want to integrate the remote changes,
hint: use 'git pull' before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
ok那我们pull一下:git pull origin master
结果有fatal: refusing to merge unrelated histories
okok,放大招吧娘的…
- push
git push origin master --allow-unrelated-histories
然后就发现推成功了。