跳至主要内容

在 Git 变基后解决合并冲突

当你执行 git rebase 操作时,通常是在移动提交。由于此操作,你可能会遇到合并冲突的情况。这意味着你的两个提交修改了同一文件的同一行,而 Git 不知道该应用哪种更改。

在使用 git rebase 重新排列和操作提交后,如果出现合并冲突,Git 会在终端打印以下信息来提示你。

error: could not apply fa39187... something to add to patch A

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Could not apply fa39187f3c3dfd2ab5faa38ac01cf3de7ce2e841... Change fake file

这里,Git 告诉你是哪次提交导致冲突(fa39187)。你有三种选择:

  • 你可以运行 git rebase --abort 完全撤销 rebase。Git 会把你的分支恢复到调用 git rebase 之前的状态。
  • 你可以运行 git rebase --skip 完全跳过该提交。这意味着问题提交引入的所有更改都不会被包含。很少会选择此选项。
  • 你可以解决冲突。

要解决冲突,你可以遵循 命令行解决合并冲突的标准流程。完成后,需要调用 git rebase --continue,让 Git 继续处理其余的 rebase。

© . This site is unofficial and not affiliated with GitHub, Inc.