Squashing first and third commits (leaving second unsquashed)
git, git-rebase, squash
Solution
I have done this:
- Cleaned my current changes (stashed).
- `git rebase -i HEAD~3`.
Edited to:
pick <2nd sha1> Second commit.
pick <1st sha1> First commit.
squash <3rd sha1> Third commit.
Solved the coflict: `error: could not apply <2nd sha1>... Second commit.`.
- `git rebase --continue`.
- Text editor was fired with the second commit message, I kept it.
- Solved the coflict: `error: could not apply <1nd sha1>... First commit.`.
- `git rebase --continue`.
- Text editor was fired with the first commit message, I kept it.
- Text editor was fired asking for a commit message for squashing the first and third commit, I typed a new message (`First commit (squashed).`).
Then it was done.
`git log --oneline`:
git log --oneline
<2nd sha1> Second commit.
<1st sha1> First commit (squashed).
I managed to do it successfully, the conflicts that occurred was supposed to happen and was easy to solve.
I am pretty satisfied with the result, but I would like to know anyway if there is any better way do achieve this.
Problem
Suppose I have the following history in my repo: ``` git log --oneline <3rd sha1> Third commit. <2nd sha1> Second commit. <1st sha1> First commit. ``` How do I squash the third commit to the first one leaving the second untouched?