报这个错就是因为你和远程库出现分叉了,具体表现是是由于同一个分支有多人修改,多人commit造成的
用户1操作 | 用户2操作 | |
T1 | git co -b brv_1 | git co -b brv_1 |
T2 | git add test2.java git commit -m 'm2' git push | |
T3 | git add test1.java git commit -m 'm1' git push Your branch and 'XXX' have diverged, and have 1 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours) | |
T4 | git pull fatal: Not possible to fast-forward, aborting. |
问题:T3时刻,提示用户git push之前需要先进行一下git pull,然而在T4时刻执行git pull时又阻止了这一操作
解决方式一:T4时刻执行git pull之前执行一下 git rebase即可
解决方式二:T4时刻执行 git push -f ,丢弃掉其它人的的修改(不推荐)