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.

有帮助吗?

解决方案

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.

其他提示

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).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top