gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 10:49:13 24 4
gpt4 key购买 nike

我创建了本地 git repo。 (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解决从这里 so ,
但我想知道是否有更清洁的方法来做到这一点?

最佳答案

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

enter image description here

enter image description here

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

解决它的最简单方法是执行以下操作:

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

最终结果是您最终获得了本地更改以及生成的 ignore 和 readme 文件。如果 Remote 上有更多更改,您可能需要进行更高级的 merge 版本,但在其他干净的 Remote 的情况下,应该这样做。

关于git - 创建 git repo 并将本地目录推送到新初始化的 Azure Repos,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59568058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com