I wanted to edit the previous commit comments because they were not written properly, but when I ran the command:
git rebase -i --root
no matter what state I chose (or even if I didn't change anything, all the commits stayed in the pick state)
It always returns an error like this:
$ git rebase -i --root
error: The following untracked working tree files would be overwritten by merge:
package-lock.json
Please move or remove them before you merge.
Aborting
hint: Could not execute the todo command
hint:
hint: pick 47377f179a6a36514f8f8ded56039160bef023aa Initial commit from Chrome Extension CLI
hint:
hint: It has been rescheduled; To edit the command before continuing, please
hint: edit the todo list first:
hint:
hint: git rebase --edit-todo
hint: git rebase --continue
Could not apply 47377f1... Initial commit from Chrome Extension CLI
The file mentioned package-lock.json
was accidentally committed to Git by my partner in the first commit, and I added it to .gitignore
to untrack it in the second commit.
In this case, I was unable to complete a rebase at all and had to force abort it.
Although I know the reason for the error, I have absolutely no idea what I should do next to avoid this error.
When I searched for a solution, the results I got were completely different from my situation.😣
Just move it out of the working tree (with a simple mv.... or rename it to something that has not been tracked ever in the project) so git does not bust it.... when the rebase is finished, get the file back.
As a tip, you might want to take the opportunity to edit
the first commit so that you remove the file from the history.
Ah.... what??? You want to correct the last commit with a git rebase --root
? That is like wanting to buy a nuclear reactor to charge your cell phone.
If what you want to do is correct the comment of the last commit, run:
git commit --amend
If you want to actually change files, just add what you want into the index, and then run:
git commit --amend --no-edit