使用git push
,根据远程仓库和本地仓库的属性不同,主要分为以下几种情况。
- 要是本地仓库比远程仓库提前,使用
git push
后,远程仓库的文件版本完全被替换成本地仓库的版本。 - 要是本地仓库比远程仓库落后,则使用
git push
后
error: failed to push some refs to 'git@code.aliyun.com:hhhdddgggg/engine.git'
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
下来,接下来本地仓库,暂存区和工作区都会被替换成远程仓库的版本。
- 要是远程仓库和本地仓库分叉,即原本远程仓库和本地仓库都是版本A,后来远程仓库对其中某些文件进行了修改,成立版本B,本地仓库对某些文件进行了修改,成了版本C。则使用
git push
后
error: failed to push some refs to 'git@code.aliyun.com:hhhdddgggg/engine.git'
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
把远程仓库的文件拉下来,再合并冲突,再git push
.
- 要是远程仓库和本地仓库都不是一个版本,则还是得先
git pull --allow-unrelated-histories
,而且得是强行拉取,解决完冲突后再合并。