Reputation: 5390
I have a commit history that looks like this:
A - B - C
Now I want the files to remain as they are, but I find that commit B
is unnecessary.
So I want the history to become:
A - C
keeping the changes introduced by B
.
Is this possible?
Upvotes: 1
Views: 301
Reputation: 66368
An easy way to do so is to do an interactive rebase, and squash two commits together:
$ git rebase -i A
This will show an editor with a screen like so:
pick A commit message
pick B commit message
pick C commit message
# Rebase A..C onto A
Simple read the options available, modify the file in your editor, and e.g.:
pick A commit message
squash B commit message
pick C commit message
pick A commit message
pick B commit message
squash C commit message
Using squash allows you to then modify the commit message to your liking (for example to use the commit message of C with the resultant commit), if the commit message is not important you can instead use fixup
.
Upvotes: 2
Reputation: 14639
You can squash commits B and C. Run git rebase -i sha1_of_A
. It will open a text editor with a list of commits. Put fixup
on the line of the C commit, save, and exit.
What will happen:
At the beginning you have:
A -B - C
L HEAD
After merging the commits you will have:
A - B - C
\ C'
L HEAD
Where C and C' will have the same files.
It means that:
B
and C
aren't actually lost, so you can get back to it if you have some remorsesUpvotes: 2