Rebase github 拉取请求

时间:2020-12-31 17:06:28

标签: rebase git-merge-conflict

我前段时间向一个项目提交了 PR,现在我需要将主分支从主树拉入我的分支并更新 PR。

这些是正确的命令吗?

git fetch upstream/master
git checkout <my_PR_branch>
git rebase upstream/master
git push

当我运行 rebase 时,我遇到了这个问题。

M   tests/testimage.h
Falling back to patching base and 3-way merge...
Auto-merging tests/testimage.h
CONFLICT (content): Merge conflict in tests/testimage.h
error: Failed to merge in the changes.
Patch failed at 0005 Fix failure message on image comparison
The copy of the patch that failed is found in: .git/rebase-apply/patch

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".

Igors-MacBook-Air:wxFork igorkorot$ git add tests/testimage.h 
Igors-MacBook-Air:wxFork igorkorot$ git rebase --continue
Applying: Fix failure message on image comparison
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

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".

1 个答案:

答案 0 :(得分:0)

难题的一部分是通过获取文件的上游版本解决了冲突。

这是提交中唯一更改的文件。通过使用文件的上游/主版本,提交现在没有变化。这是一个空提交。

No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.

提交现在是空的,跳过它。 git rebase --skip


您的更新程序基本正确。有两个错误。

git fetch 需要一个远程分支,而不是远程分支。 git fetch upstream 更新所有上游分支,或 git fetch upstream master 仅获取上游/主分支。 git fetch 非常有效;除非您的带宽非常宝贵,或者上游分支特别臃肿,否则请养成获取所有内容以保持简单的习惯。

git push 只会将提交添加到称为“快进”的分支。您想将分支指向一组新的提交(rebase 不会重写提交,它会生成新的提交)并且 git push 将拒绝这样做。而是使用 git push --force-with-lease--force-with-lease is safer than --force

  • git fetch 上游
  • git checkout
  • git rebase 上游/主
  • git push --force-with-lease
相关问题