Search code examples
gitgit-rebase

editing commits with git rebase


I'm having a problem with editing commits.

I have 2 commits for 2 .php files. My goal is to edit them both. I read about rebase -i and this is what I reckon is supposed to be done:

  • first I change pick to edit;
  • save and exit;
  • rebase stops;
  • type git commit --amend;
  • make changes, save and close the text editor;
  • type git rebase --continue.

After this I believe the rebase stops again and I have to do this all over again for the second commit.

But right after I type git rebase --continue i get this:

file1.php: needs update
You must edit all merge conflicts and then
mark them as resolved using git add

What is the problem and what do I do?


Solution

  • When you stop for the rebase you have to:

    • edit a file(s)
    • add changes to the index - git add changedFile
    • amend changes - git commit --amend
    • continue rebasing - git rebase --continue

    From your description it is possible that you forgot to add changes to the index. In that case git commit --amend does nothing (there is no changes to amend). In addition you have git commit --amend before you edit the file which is also wrong (you have to amend changes you already did on the file).

    Try to apply steps in the order I gave.