问题
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
回答1:
Your attempt to rebase
with squash
has not failed. What you see not an error.
Your rebase operation has been paused.
Read carefully the message:
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".
Could not apply ccdfa7670a8eb780954edd1383e3378ef43292ac... Add readme.md
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:
commit c0ad7755f58f1bef92d71b72b8e1397b9e07fdea
Merge: ccdfa76 b1ba9e4
Author: Prince Rolf
Date: Tue March 2 19:07:32 2017 -0500Merge branch 'sports-module' of gitlab.cell.com:grp-imco-products/im-lap-sports into sports-module
# Conflicts:
# README.md
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 commit ccdfa76
(the one we have problem with) and b1ba9e4
(unknown so far).
Now look at the tree of commits, let's look for those commit IDs.
* 04dc4d0 play: wip sports
* c0ad775 Merge branch 'sports-module' of gitlab.paper.com:chain/catch-sports into sports-module
|\
| * b1ba9e4 play: sports
| * a2464b1 adding sports files
| * 1a3cc30 play: wip sports
* ccdfa76 (origin/master) Add readme.md
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 of a2464b1
which in turn sits on top of 1a3cc30
- 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 the ccdfa76
(problematic one) which is 'aside' the rest.
Now, let's look at the start of your rebase command:
git rebase -i 1a3cc30
pick ccdfa76 Add readme.md
squash a2464b1 adding sports files
squash b1ba9e4 play: sports
squash 04dc4d0 play: wip sports
squash f255d38 play: sports
Detailed command are not important right now. What's important is the effective sequence of commits that you requested:
0: 1a3cc30 \ (rebase root)
1: ccdfa76 ---:----- (problematic one)
2: a2464b1 |
3: b1ba9e4 /
-:(c0ad775) (merge, not mentioned in rebase plan, so not requested)
4: 04dc4d0 ...
5: f255d38 ...
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 the c0ad775 merge
glued these two tree parts together and it had a conflict at 'readme' file. Remember that ccdfa76
message says adding readme file
.
So now, apparently, the rebase has halted when trying to apply ccdfa76
onto 1a3cc30
with the same conflict at 'readme' file.
Apparently, ccdfa76
tries to add a readme
file, but 1a3cc30
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:
git status
# On branch FOOBAR
# You have unmerged paths.
# (fix conflicts and run "git commit")
#
# Unmerged paths:
# (use "git add ..." to mark resolution)
#
# both added: readme.md
#
no changes added to commit (use "git add" and/or "git commit -a")
Alright, so there's really conflict at this readme file. Now you can fix it. Open that file, find markers like
bum
<<<<<
bleh
=====
blah
>>>>>
whooo
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:
git add readme.md
Yes. That's just plain old add
. After that, use the command that was suggested in the "error message":
git rebase --continue
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:
> git rebase -i 1a3cc30
(...)
error: cannot apply (..)
> git status
(....)
#aha! I see a conflict at "readme.md"
(...)
> vim readme.md #edit, fix, save
> git add readme.md # tell Git that file is OK now
> git rebase --continue # tell git to get back to work
# now either it's ok, or another conflict - rinse and repeat until finished
来源:https://stackoverflow.com/questions/43826650/error-could-not-apply-tried-it-in-proper-way-by-seeing-instructions-but-st