10

I am rebasing a branch of several commits onto an upstream branch. I am blocked by a failure of some kind where I can't continue to the remaining commits in my branch, so I need a way to continue when git reset does not seem to work.

As I said I'm rebasing a branch. I do rebasing like this all the time, and I am not surprised that one or two commits have conflicts that resolve down to empty commits. But I don't know which commits until I go through the conflict resolution steps (editing the files that conflict and adding the resulting files). So here's an abstracted version of what happened:

$ git checkout working_branch
$ git rebase -i upstream
 [Here it is reported that file.c has conflicts. I edit it.
  The resulting diff is empty.]
$ git add file.c
$ git rebase --continue
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:

  git commit --allow-empty

Otherwise, please use 'git reset'
rebase in progress; onto xxxsha

However at this point git reset is of no help, I end up with the same exact status. I don't wish to have an empty commit. I have come upon potential empty commits from this process before and I have always been very happy to have the commit disappear.

I came upon the question git cherry-pick not working in which almost the same exact results occur, but from cherry-picking one commit, not rebasing a branch. The other inquirer was happy to just go ahead and not do the cherry-pick. Stepwise I guess rebase uses cherry-pick for each commit, I have several commits to step through. In my case this happened on the first commit of my branch and I need a real solution to continue.

cardiff space man
  • 1,442
  • 14
  • 31

2 Answers2

14

The take-away is to look carefully at the summary line. The answer turns out to be git rebase --continue if you notice that the summary line of the commit it says cannot be applied, is actually the next commit. I was thrown off by how similar the text on screen was to the usual empty commit message that the command often shows. But it was a different kind of message. It had in fact continued on, and was working on the next commit, which was automatically resolved as empty. The text included the summary line from the next commit of the branch, instead of the summary line from the commit I had just resolved. So when the empty commit status comes up in this way, it is okay to just continue again without further ado.

cardiff space man
  • 1,442
  • 14
  • 31
8

After you're done resolving the conflicts and discover you're left with an empty commit, you could just skip it:

$ git rebase --skip
Mureinik
  • 297,002
  • 52
  • 306
  • 350