创建git repo并将本地目录推送到新初始化的Azure Repos

问题描述 投票:0回答:1

我创建了本地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.

所以我先尝试了pullgit 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处通过so解决,但我想知道是否有更清洁的方法?

git azure-devops azure-repos
1个回答
0
投票

当您在Azure DevOps上创建新存储库时,可以选择对其进行初始化,也可以将其保留。初始化存储库时,Azure DevOps将添加一个.gitIgnore和一个readme.md

enter image description here

enter image description here

这通常是您看到的推/拉问题的原因。

解决它的最简单方法是:

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

最终结果是您最终进行了本地更改and生成的忽略和自述文件。如果遥控器上有更多更改,则可能需要执行更高级的合并,但是如果使用的是干净的遥控器,则应该这样做。

© www.soinside.com 2019 - 2024. All rights reserved.