Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: how to melt a commit to another commit? [duplicate]

Tags:

git

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
like image 481
exec Avatar asked Sep 07 '26 20:09

exec


1 Answers

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)
like image 94
Philippe Avatar answered Sep 10 '26 09:09

Philippe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!