My commit log is like:
git rebase -i HEAD~3
drop 951f869 add2
pick cbf7e72 add3
pick 1e17b83 add4
error: could not apply cbf7e72... add3
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".
diff --cc test
@@@ -1,1 -1,3 +1,7 @@@
++>>>>>>> cbf7e72... add3
It might be easier to explain if we use some text in the lines of code. I'll just create a file with each commit adding a new line with the corresponding commit. e.g.
final file looks like this:
First Line Second Line Third Line Fourth Line
Then when I do the interactive rebase, I'll get this prompt:
<<<<<<< HEAD First Line ======= First Line Second Line Third Line >>>>>>> 8ba3272... Added Third Line
Everything above ============= is the original, and everything after was the state after the third commit. There is a merge conflict because it's trying to add a line to the third line, and there isn't one yet. So this is where you would need to resolve the conflict. If you want the output to be:
First Line Third Line
You would just need to delete the <<<<<<< and >>>>>>>>>>>>>> markers and enter how you would want the file to look, then do a
git add then
git rebase --continue.
Then it would try to add the 4th commit, and you'd get another merge conflict because it's trying to add a fourth line. So you'd just need to resolve that conflict in the same way. Followed by another
git rebase --continue to finish the interactive rebase.
The final file should look like this:
First Line Third Line Fourth Line
git log would show this (the commit adding the second line has been removed):
commit 9064bd9d9efece49c0cf2dacd41be98e8cb70d01 Author: Kief Kraken Date: Thu Sep 29 11:05:44 2016 -0700 Added fourth Line commit cdcd1a33fb7b41e583fdb8098b266b0fb6898aca Author: Kief Kraken Date: Thu Sep 29 11:05:21 2016 -0700 Added Third Line commit 7744551b481d4c6f7f5da038c56f3044d8b000d2 Author: Kief Kraken Date: Thu Sep 29 10:52:20 2016 -0700 Added first line commit e8e76881002e361401bbaaa22140660ed026fd04 Author: Kief Kraken Date: Thu Sep 29 10:51:56 2016 -0700 first commit
While this is good for an exercise learning about interactive rebasing, I would strongly recommend using a merge tool that makes managing these tasks much easier and give less room for error.