0

I submitted a PR some time ago to a project and now I need to pull the master branch from the main tree into my branch and update the PR.

Are those the right commands to do that?

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

When I ran the rebase I had this problem.

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".
Schwern
  • 153,029
  • 25
  • 195
  • 336
Igor
  • 5,620
  • 11
  • 51
  • 103

1 Answers1

0

The missing piece of the puzzle is the conflict was resolved by taking the upstream version of the file.

This was the only file changed in the commit. By using the upstream/master version of the file, the commit now has no changes. It is an empty commit.

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.

The commit is now empty, skip it. git rebase --skip.


Your update procedure is basically correct. There's two mistakes.

git fetch takes a remote, not a remote branch. Either git fetch upstream to update all upstream branches, or git fetch upstream master to only fetch upstream/master. git fetch is very efficient; unless your bandwidth is at a premium, or there's a particularly bloated upstream branch, make it a habit to fetch everything to keep it simple.

git push will only add commits to a branch known as a "fast-forward". You want to point the branch at a new set of commits (rebase does not rewrite commits, it makes new ones) and git push will refuse to do that. Instead use git push --force-with-lease. --force-with-lease is safer than --force.

  • git fetch upstream
  • git checkout <my_PR_branch>
  • git rebase upstream/master
  • git push --force-with-lease
Schwern
  • 153,029
  • 25
  • 195
  • 336
  • please the OP edit. I did fix the conflict, saved the file, then used `git add` and then `git rebase --continue` failed. Any suggestions? – Igor Jan 03 '21 at 03:44
  • @Igor How did `git rebase --continue` fail? Note that if there's a conflict between your PR and master, *Github* should tell you in the PR. If Github says it will merge fine, but Travis says there's a conflict, the problem is likely Travis. But Travis shouldn't be doing any merging, it should only test your branch. A potential merge conflict should not affect compiling the branch. We need more information. – Schwern Jan 03 '21 at 04:06
  • I updated the OP. For some reason the edit didn't show up before. – Igor Jan 03 '21 at 04:11
  • also just to clarify - I'm doing all this on my local GitHub fork and not on the remote repository. – Igor Jan 03 '21 at 04:13
  • @Igor So, this has nothing to do with Travis nor Github. It's just a conflict resolution problem? First, show us `git status` when you're in that state. – Schwern Jan 03 '21 at 04:47
  • @Igor I see. By running `git add tests/testimage.h` you've simply added the conflicted file, that's what Git means by "no change". When there's a conflict you have to resolve the conflict. That means editing the file, finding the conflict markers, and choosing what to do. See [Basic Merge Conflicts](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging). – Schwern Jan 03 '21 at 04:51
  • the original problem was: I submitted a pull request to a project on Github from the forked repository. And now I want to make the branch that PR was submitted to be from the current upstream. But it looks like I'm having trouble updating my branch with the upstream master. – Igor Jan 03 '21 at 04:53
  • @Schewern, this is exactly what I did. I kept the version from the upstream master, in my branch. But `git` refuses to add it – Igor Jan 03 '21 at 04:55
  • @Igor Did you edit tests/testimage.h to resolve the merge conflict? It looks like you added it with no edits. See my updated answer. – Schwern Jan 03 '21 at 04:59
  • yes, I did I now have the copy just like in the upstream master. – Igor Jan 03 '21 at 05:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/226761/discussion-between-schwern-and-igor). – Schwern Jan 03 '21 at 05:04