git push 报错:Updates were rejected because the remote contains work that you do
not have locally
git push To https://urlxxxxxxxxxxxxxx ! [rejected] xxxx -> xxxxx (fetch first) error: failed to push some refs to 'https://urlxxxxxxxxxxxxxx'
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.
拉取更新
git pull origin xxxx
拉取更新报错: You have divergent branches and need to specify how to reconcile them
git pull origin branch_xxx
remote: Azure Repos
remote: Found 9 objects to send. (4 ms)
Unpacking objects: 100% (9/9), 850 bytes | 283.00 KiB/s, done.
From https://url_branch_xxxx
* branch branch_xxxx -> FETCH_HEAD
3c574a7f127..f8b99bb4d92 branch_xxxx -> origin/branch_xxxx
hint: You have divergent branches and need to specify how to reconcile them.
hint: You can do so by running one of the following commands sometime before
hint: your next pull:
hint:
hint: git config pull.rebase false # merge (the default strategy)
hint: git config pull.rebase true # rebase
hint: git config pull.ff only # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories. You can also pass --rebase, --no-rebase,
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
fatal: Need to specify how to reconcile divergent branches.
使用合并(merge)
如果您希望在本地分支和远程分支之间进行合并,可以运行以下命令:
git config pull.rebase false
然后再次尝试 git pull
:
git pull origin branch_xxx
这种方法会保留所有的提交历史,并会生成一个新的合并提交。
使用重放(rebase)
如果您想要将本地的提交放置到远程分支的后面,从而拥有更整齐的提交历史,可以选择重放:
git config pull.rebase true
然后再次尝试 git pull
:
git pull origin branch_xxx