上面一篇文章写了git rebase 如何操作,但是,有时候我们代码可能会出现冲突,怎么解决呢?
出现的问题:
git rebase -i master
Auto-merging APP-META/docker-config/Dockerfile_testing
CONFLICT (content): Merge conflict in APP-META/docker-config/Dockerfile_testing
Auto-merging APP-META/docker-config/Dockerfile_staging
CONFLICT (content): Merge conflict in APP-META/docker-config/Dockerfile_staging
Auto-merging APP-META/docker-config/Dockerfile_production
CONFLICT (content): Merge conflict in APP-META/docker-config/Dockerfile_production
error: could not apply 1479a8f5… update base image
Resolve all conflicts manually, mark them as resolved with
“git add/rm <conflicted_files>”, then run “git rebase --continue”.
You can instead skip this commit: run “git rebase --skip”.
To abort and get back to the state before “git rebase”, run “git rebase --abort”.
Could not apply 1479a8f5… update base image
解决方案:
1.先 git rebase --abort
2.先 git status 查看一下状态,对有有冲突的文件,先修改一下,修改完之后,
(APP-META/docker-config/Dockerfile_production 这个是需要修改的文件)
2.$ git diff APP-META/docker-config/Dockerfile_production
3.git add APP-META/docker-config/Dockerfile_testing
4. git rebase --continue
5. esc :wq
6. 如果还有问题,继续上面查看status,修改文件,git diff 文件,git add 文件, git rebase --continue esc :wq,直到没有冲突为止
7.git push -f origin 我的当前分支
完美解决!
补充:如果是前端代码,可能在rebase之后会出现如下问题:
解决方案:重新checkout一下,还原文件,继续 rebase 就可以了。