记录git push / pull报错解决

249 阅读2分钟

开开心心提交报错

当我写好一个功能,正准备git add . git commit -m 'fix' git push 三步走时。git push却报错了

xuehao@B-V32YML7L-0130 creator-773 % git push To gitlab.alibaba-inc.com:bloom-pages/creator-773.git ! [rejected] daily/1.0.9 -> daily/1.0.9 (fetch first) error: failed to push some refs to 'gitlab.alibaba-inc.com:bloom-pages/creator-773.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,谁想到

xuehao@B-V32YML7L-0130 creator-773 % git pull remote: Enumerating objects: 128, done. remote: Counting objects: 100% (128/128), done. remote: Total 128 (delta 0), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (128/128), 82.66 KiB | 1019.00 KiB/s, done. From gitlab.alibaba-inc.com:bloom-pages/creator-773 3de1b41..314aaa8 daily/1.0.9 -> origin/daily/1.0.9

  • [new branch] def_releases_2024042420514242_bloom-pages_creator-773/1.0.9 -> origin/def_releases_2024042420514242_bloom-pages_creator-773/1.0.9 47a103e..adca5f9 master -> origin/master
  • [new tag] publish/1.0.8 -> publish/1.0.8 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 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.

解决方法

执行以下命令

  1. git reset --soft HEAD^ [将HEAD指针会退到上一个提交,但不会影响工作目录,暂存区和工作目录中的更改保持不变]
  2. git stash [相当于git stash save,当前分支应该回回到上一个提交的状态,左右的更改都被安全地保存在stash中]
  3. git pull
  4. git stash apply [用于将之前保存的stash应用回到工作目录中]
  5. git add .
  6. git commit -m 'fix'
  7. git push