pauljohn32
pauljohn32

Reputation: 2255

git rebase: explain how to do better?

I had a weird rebase experience today. I don't understand what went wrong. Could you please review and see if I made any obvious mistakes. The end result seems OK, but I just don't understand how I should have done this differently.

I wanted to pull some changes by a colleague, but had changes I did not yet commit. So I first commit my changes:

$ git commit -a -m "variablekey::assignMissing zapspace after semi-colon separation"
[master d8b462f] variablekey::assignMissing zapspace after semi-colon separation
3 files changed, 11 insertions(+), 3 deletions(-)

I used pull with rebase. I wanted to pull all updates and then apply my commits on top of them.

$ git pull --rebase
X11 forwarding request failed on channel 0
First, rewinding head to replay your work on top of it...
Applying: variablekey::assignMissing zapspace after semi-colon separation
Using index info to reconstruct a base tree...
M       package/kutils/R/variableKey.R
Falling back to patching base and 3-way merge...
Auto-merging package/kutils/R/variableKey.R
CONFLICT (content): Merge conflict in package/kutils/R/variableKey.R
error: Failed to merge in the changes.
Patch failed at 0001 variablekey::assignMissing zapspace after semi-colon separation
The copy of the patch that failed is found in: .git/rebase-apply/patch

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

That's to be expected. I edited the file "variableKey.R". I found the section with <<==>> around it and corrected the code. After editing the file, I run

$ git add .

$ git commit -m "Edited variableKey to resolve conflicts"
 [detached HEAD dbc8e16] Resolved merge conflict
 5 files changed, 500 insertions(+), 4 deletions(-)
 create mode 100644 package/kutils/R/cfaTable.R-pj
 create mode 100644 package/kutils/R/import-1.R

$ git rebase --continue
Applying: variablekey::assignMissing zapspace after semi-colon separation
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.

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

It finds no changes and wondered if I ran git add, but I did.

$ git status .
rebase in progress; onto 2a68a60
You are currently rebasing branch 'master' on '2a68a60'.
 (all conflicts fixed: run "git rebase --continue")

nothing to commit, working tree clean

The manual here: https://help.github.com/articles/resolving-merge-conflicts-after-a-git-rebase cautions against that, saying "You can run git rebase --skip to completely skip the commit. That means that none of the changes introduced by the problematic commit will be included. It is very rare that you would choose this option."

I ended up running "git rebase --skip" anyway.

I find that these git features which I use only two or three times per year are tricky, I forget the nuances.

Upvotes: 0

Views: 122

Answers (1)

mkrieger1
mkrieger1

Reputation: 23142

After adding the file with the resolved conflict to the index, the normal way to proceed would have been to git rebase --continue directly.

By creating a new commit first, you "took away" the commit from the rebase, so that when it tried to apply it, there was nothing left to do.

Upvotes: 4

Related Questions