场景1:本地pull服务器出错
当我用gitbash从服务器拉取代码时,出现了文件冲突。
git pull $ git pull error: Your local changes to the following files would be overwritten by merge: A3_find_best_k.py Please commit your changes or stash them before you merge.
刚开始时,A3_find_best_k.py是本地和服务器均相同的文件,但是之后,本地文件A3_find_best_k.py修改了,同时服务器端的代码也修改了,导致此次合并是两个版本的合并。
解决方法
第一步
git stash 先把当前的修改暂存起来 git pull 再拉取远程代码
第二步
git stash list 查看 对于stash后的分支,有三种处理方法,任选其一 git stash drop 删除stash内容,保留pull的结果为最终分支 git stash apply 恢复stash为最终分支 但stash中内容不删除 git stash pop 恢复stash为最终分支,同时把stash内容也删除
场景2:本地push到服务器出错
服务器包含本地没有的文件,
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再push
|