I am new to git and I tried to squash my commits.
In my branch, it shows my 32 commits (John Smith), within that three commits of another two developers too (Prince Rolf and Harry).
For one commit a developer has amended.
Now if I try to squash all the commits I am getting an error:
error: could not apply ccdfa76... Add readme.md
I googled for the error, but was not able to find it.
I tried squashing by ten and then ten but that also throwing error.
Can you guys tell me how to swim it providing the error below?
$ git rebase -i aaaa
pick 04dc4d0 play: wip sports
pick f255d38 play: sports
Your attempt to
rebase
withsquash
has not failed. What you see not an error.Your rebase operation has been paused.
Read carefully the message:
Look at the commands suggested.
rebase / continue
,rebase / skip
,rebase / abort
. This essentially tells you that the rebase is still ongoing. It is paused. You can ignore the problem and skip, you can do something and continue, or you can abort (and rollback) the rebase completely.Ok. So we know what's the situation. Now, let's check WHY.
If you read the message, you know it's "cannot apply ccdfa(..)".
You could not check the status, index, etc, to see what's up, but you has not shown them. So, for now let's use what you gave us already.
If to read things really carefully, we can notice this note in the git log:
Look at the shouting "CONFLICTS". It's not a thing you often see in the commit message. That's commit
c0ad77(..)
(not the one we have problem with), but as you can see in its headers, this is a merge of the commitccdfa76
(the one we have problem with) andb1ba9e4
(unknown so far).Now look at the tree of commits, let's look for those commit IDs.
Hey, all of them happen to be at the very start of the history (bottom). Great. It will simplify looking at them.
That
b1ba9e4
sits on top ofa2464b1
which in turn sits on top of1a3cc30
- and that's the rebase root you wrote in your rebase command.c0ad775
is indeed a merge between the part that contains rebase-root and theccdfa76
(problematic one) which is 'aside' the rest.Now, let's look at the start of your rebase command:
Detailed command are not important right now. What's important is the effective sequence of commits that you requested:
Looking at the commit tree, you try to inject the
ccdfa76
(left side of tree) into the middle of right side of tree. Remember that thec0ad775 merge
glued these two tree parts together and it had a conflict at 'readme' file. Remember thatccdfa76
message saysadding readme file
.So now, apparently, the rebase has halted when trying to apply
ccdfa76
onto1a3cc30
with the same conflict at 'readme' file.Apparently,
ccdfa76
tries to add areadme
file, but1a3cc30
already has a readme file. Hence conflict.That's my guess. Now let's get to the console.
Now start over, cleanup everything.
Do your rebase command with the same plan as before (pick/s/s/s/s/s.../s).
Wait until
cannot apply ccdfa(..)
shows up.Remember that rebase is not faulted - it is paused so you can fix it and continue.
Now run
git status
and see what it says.It should say something like:
Alright, so there's really conflict at this readme file. Now you can fix it. Open that file, find markers like
This are merge conflicts markers. I wont explain how they work. Read about it online, or just use a merge tool of sorts (like i.e. KDiff3 or WinMerge or whatever).
The most important point is: edit the file and make sure it looks like you want it to look. When you end editing, there should be no markers inside.
When you finish fixing the conflict, run this to tell git that the conflicts in this file were all fixed:
Yes. That's just plain old
add
. After that, use the command that was suggested in the "error message":and the rebase will take your fixed file, and ..continue. Most probably, it will then run to the end.
Or will hit into another conflict in the same or another file, which you will need to fix in a similar way, and continue, and so on.
Be careful - whenever
rebase
pauses, there may be many files under conflict. Git Status will show them all. Also, when fixing conflicts, remember that there may be many conflicts in a single file (many markers in various parts of the file).Summing up, commandline activity looks like this: