4

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?

halfer
  • 18,701
  • 13
  • 79
  • 158
EmptyClip
  • 43
  • 1
  • 4

2 Answers2

7

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.

Marcin Zajączkowski
  • 3,776
  • 1
  • 26
  • 39
  • I gave it a try. I changed the file, did the 'git add', did the '--amend' and the '--continue'. Then i got this error: could not apply 21e61c9... second commit. Git then refers me to --continue, --skip and --abort commands. – EmptyClip Jan 19 '14 at 01:10
  • That error is expected when your change conflicts with the original changes in the following commits. Call `git status` to see how does it look like. Pay attention to the line with `both modified`. – Marcin Zajączkowski Jan 19 '14 at 01:19
  • # HEAD detached from 7deb658 # You are currently rebasing branch 'master' on '7deb658'. # (fix conflicts and then run "git rebase --continue") # (use "git rebase --skip" to skip this patch) # (use "git rebase --abort" to check out the original branch) # # Unmerged paths: # (use "git reset HEAD ..." to unstage) # (use "git add ..." to mark resolution) # # both modified: show-dir-content.php – EmptyClip Jan 19 '14 at 01:25
  • As predicted you have a conflict in `show-dir-content.php`. Did you make a change in this file which can conflict/overlap with the changes in the following commits? Try to [resolve](http://stackoverflow.com/a/163659/313516) it. – Marcin Zajączkowski Jan 19 '14 at 01:28
  • Yes, i made changes in the file, my task IS to make changes to both files I previously committed. I'll look for a solution in the link you provided. – EmptyClip Jan 19 '14 at 01:31
  • Modifying both files is not a problem. A problem (difficulty) could be to modify in a rebase of the first file a line which is already modified in the second original commit. Then a conflict occurs. It is a logical problem when you have to decide what change should be take into consideration. Git (and other SCM tools) provides the ways to handle it. – Marcin Zajączkowski Jan 19 '14 at 01:52
1

(Posted solution on behalf of OP).

I got the right way to do it:

git rebase -i --root (I wasn't able to find both commits using HEAD~2)
pick->edit for both commits
Ctrl+X and Y and ENTER
edit the first commit
git add file1.php
git commit --amend
git rebase --continue
edit the second commit
git add file2.php
git commit --amend
git rebase --continue
git push -f

Hope this helps at least one person starting their git experience. Szpak, you've been a big help. Thanks.

Tim
  • 38,263
  • 17
  • 115
  • 131
halfer
  • 18,701
  • 13
  • 79
  • 158