我创建了本地git回购。(git init,git add,git commit)。然后,我在Azure DevOps上创建了git repo。我也在本地执行git remote add origin <azure_repo_url>
现在,当我尝试git push origin master
返回时:
To azure_repo_url
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'azure_repo_url'
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.
因此,我pull
先尝试:git pull origin master
但又回来了:
$ git pull origin master
warning: no common commits
remote: Azure Repos
remote: We noticed you're using an older version of Git. For the best experience, upgrade to a newer version.
remote: Found 3 objects to send. (27 ms)
Unpacking objects: 100% (3/3), done.
From azure_repo_url
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
fatal: refusing to merge unrelated histories
我可以解决它git pull origin master --allow-unrelated-histories
从这里如此,但我不知道是否有清洁的方式做到这一点?
在Azure DevOps上创建新存储库时,可以选择对其进行初始化,也可以不进行任何选择。初始化存储库时,Azure DevOps将添加一个.gitIgnore
和一个readme.md
。
通常,这是您看到的推/拉问题的原因。
解决此问题的最简单方法是:
git remote add origin <azure_repo_url>
git fetch origin
git rebase master --onto origin/master
... fix any merge conflicts ...
git push origin master
要么:
git remote add origin <azure_repo_url>
git pull --rebase
... fix any merge conflicts ...
git push origin master
最终结果是您将进行本地更改并生成了忽略和自述文件。如果遥控器上有更多更改,则可能需要执行更高级的合并,但是如果使用的是干净的遥控器,则应该这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句