在 Debian 上处理 GitLab 冲突的实用步骤
一 准备与环境检查
sudo apt-get update && sudo apt-get install -y git。git clone <repository-url> && cd <project>。git pull origin <branch-name>;如需新建分支开发:git checkout -b <new-branch-name>。sudo apt-get install -y gitlab-runner && sudo gitlab-runner verify,必要时查看日志:sudo gitlab-runner logs。这些步骤能减少因环境或版本导致的合并异常。二 本地命令行解决冲突的标准流程
git pull origin <branch-name>。git status,冲突文件中会出现标记:<<<<<<< HEAD、=======、>>>>>>> <branch-name>。git add <resolved-file>(或 git add .)。git commit -m "Resolve merge conflict"。git push origin <branch-name>。三 使用网页编辑器或 VS Code 可视化解决
git remote update -p;切换到你的分支:git checkout <your-branch>;将目标分支(如 develop/main)合并进你的分支:git merge <target-branch>;在 VS Code 的源代码管理中点击冲突文件,使用三窗格视图选择并保留更改,保存后 git add .、git commit -m "Resolve conflicts"、git push origin <your-branch>,回到 GitLab 完成 MR。四 进阶场景与回退策略
git fetch 后执行 git rebase origin/develop,遇到冲突时解决,然后 git rebase --continue,最后 git push -f origin <your-branch>(仅在个人分支且团队允许强制推送时使用)。git merge --abort 中止合并,回到干净状态再处理。git reset HEAD~1 回退(可多次),整理后再 git rebase 并 git push -f(谨慎操作,确保不会影响他人)。五 常见报错与排查要点
git pull --rebase(或普通 git pull)再解决冲突、提交并推送。git status,解决后 git add、git commit。git merge --abort 回到合并前状态。git rebase --continue,不要遗漏此步。sudo gitlab-runner verify 与 sudo gitlab-runner logs 定位 Runner 问题,确保流水线可正常执行。