Reputation: 4862
I want to merge two commits. One is farther back and the other is the recent one in my git history. Here is my last 12 commits in a branch (not in master).
$ git log -12 --pretty=oneline
47c724a6fdbb6a0b6d51cd42d0bde92c23a0d32e L
9446932bc6e13d0437ab6b3f03161e3c2bca0f62 K Follow up of A
842e6a97284a02a70122d50f2f647a51b0e5cce7 J
77a0e99a62d9f77044cc37cbe22870b11c83f046 I
a125f0f701732a2dbd0cfe85c65583c46d1c67fa H
544b241dfe56e3b548af04c4d7c6e2092f3e108d G
7e5a649681a97f23c11716e8c87dfb1cc7d6125d F
d5378ec4216dce45dc0fc4a4ea1c0e4dac41a329 E
8d0420fd97178908db966a03d58252d5fb2b1c82 D
0e4425a86ce522a1a25886587c57379c1b4522ff C
5cba291aba6bb10749e1f1d4e0970d7e42decc17 B
2ba31cd61724f14f84a1a0a3e26e788374c62f9d A
There are many commits before A, but I think they are off-topic here and I did not list them.
I want to merge A and K. If possible, I want to delete A or K or both after merge. I've found some questions here about git rebase --interactive
. I tried git rebase -i HEAD~12
and I was brought into VIM. Then, I'm stuck and I can't proceed.
edit
on K, but it seems editing the commit message only. squash
on A and K, but I got Cannot 'squash' without a previous commit
. It seems squashing two subsequent commits only.Can you please advice what I should do here? I'm free to push -f
to the remote branch.
Upvotes: 0
Views: 56
Reputation: 40041
With rebase -i HEAD~12
you'll get your commits in order A (at the top) to L (at the bottom. Just re-order them so that K follows on A and instead pick choose fixup and save that buffer and exit vi.
pick 2ba31cd61724f14f84a1a0a3e26e788374c62f9d A
fixup 9446932bc6e13d0437ab6b3f03161e3c2bca0f62 K Follow up of A
pick 5cba291aba6bb10749e1f1d4e0970d7e42decc17 B
pick 0e4425a86ce522a1a25886587c57379c1b4522ff C
pick 8d0420fd97178908db966a03d58252d5fb2b1c82 D
pick d5378ec4216dce45dc0fc4a4ea1c0e4dac41a329 E
pick 7e5a649681a97f23c11716e8c87dfb1cc7d6125d F
pick 544b241dfe56e3b548af04c4d7c6e2092f3e108d G
pick a125f0f701732a2dbd0cfe85c65583c46d1c67fa H
pick 77a0e99a62d9f77044cc37cbe22870b11c83f046 I
pick 842e6a97284a02a70122d50f2f647a51b0e5cce7 J
pick 47c724a6fdbb6a0b6d51cd42d0bde92c23a0d32e L
Upvotes: 1