Question

I have a peculiar commit log which looks like that,

A --> B --> C --> D

where each letter is a commit. It appears that C is a revert of B, so basically the history would be the same as

A --> D

Is there a way to "sum" the B and C commits ? The changes haven't been pushed yet.

Était-ce utile?

La solution

You can do git rebase -i HEAD~3 and remove the lines representing the B and C commits in the TODO list and do the rebase.

Autres conseils

Aside from the interactive rebase, an easy way to do it is:

git reset --hard A     # reset current branch to A
git cherry-pick D      # transplant commit D here

There is also a more general command, which will work better when C-D is a whole range of commits:

git rebase --onto A C  # transplant C..D onto A

the easiest way to do this is with reset:

git reset --soft HEAD^^^
git add -A
git commit -C HEAD@{1}

The first command takes makes A the current commit while keeping the working tree like it was in D. We stage the state of the work tree with the next command. Next, we commit using the message from commit D (where HEAD was 1 time ago).

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top