Reputation: 2011
I have 3 commits and i want to skip a commit -2 while rebasing into 1 say
commit -1
commit -2
commit -3
i did git rebase -i HEAD~3
pick commit -1
pick commit -2
squash commit -3
i tried like this (removed the pick commit -2) but that deleted the commit -2 itself from git log :(
git rebase -i HEAD~3
pick commit -1
squash commit -3
Someone please help me how can i squash commit 1 and commit 3 using command only.
Upvotes: 5
Views: 2916
Reputation: 12237
Easy, reorder the lines:
pick 1
squash 3
pick 2
This will rebase the history squashing 3 into 1 and moving commit 2 after.
From the help text:
These lines can be re-ordered; they are executed from top to bottom.
# Rebase 25c328e..a038737 onto 25c328e (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
Upvotes: 2
Reputation: 13589
If I'm understanding correctly, just reorder the commits:
pick commit -1
squash commit -3
pick commit -2
This would place commit -2
after -1
and -3
; put -2
on top if you want it to come before. (Commits are evaluated top to bottom.)
Upvotes: 9
Reputation: 1091
If you don't care about the history of the branch and the commits; you can start a branch from commit-4; cherry pick 1 and 3, squash them and then cherry pick commit-2. You will be on a new branch but it will have the end result you need. Also, I assumed the commits would not have conflicts.
commit-1
commit-2
commit-3
commit-4
git checkout commit-4
git checkout -b newbranch name
git cherry-pick commit-3 commit-1
git rebase and do the squash
git cherry-pick commit-2
Upvotes: 0