3

Let's say I have git commit history like this(newer -> older):

C -> B -> A

after C's commit, I came to realize that there is something wrong with A.Maybe a test case which is suppose to be in that commit,but actually it wasn't there. So how can I deal with this situation? Make a new commit and melt it into A?how?

Problem solved:

  1. git checkout A
  2. git checkout -b fix
  3. edit
  4. git add files
  5. git commit --amend
  6. git rebase fix master
exec
  • 65
  • 5
  • 1
    You could branch from A, make your commit, and then rebase B+C on top of it. – Oliver Charlesworth May 24 '15 at 16:49
  • make a new commit D that fixes the problem inside A in a new branch. Then do `git rebase --interactive`. This will allow you to re-order the commits you made (sort it so that it is C->B->D->A). Be careful: this is rewriting the commit history and you will run into problems if other people already pulled you branch – Slizzered May 24 '15 at 16:50

1 Answers1

2

A lot of persons will said to you to do rebase --interactive (which could be the solution) but if you plan to change some lines that had been changed in commits B or C, that will be a hell to use.

The another solution could be :

  1. Create and checkout a branch on commit A
  2. Amend the commit A or create a new commit (depend on what sense you give to what you want to do)
  3. Checkout the previous branch which is still on commit C
  4. Use rebase --onto to rebase only commit B and C on the newly created branch (that you could delete after)
Philippe
  • 28,207
  • 6
  • 54
  • 78