user9124444
user9124444

Reputation:

Git rebasing from commit N to commit B

Is is possible to rebase only specific commits out of a list of N commits?

I have 36 commits in total, and would like to squash from commit 36 to commit 12 lets say (from 36 to 12 they are all one user's commits and all are for a single feature), how to do that ?

Upvotes: 1

Views: 53

Answers (1)

hsirah
hsirah

Reputation: 347

You can use interactive rebase to do this.

git checkout <branch_with_commits>
git rebase -i HEAD~36

This will open an editor with all the commits being rebased along with the action to be performed for each commit like this:

pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file

# Rebase 710f0f8..a5f4a0d onto 710f0f8
#
# 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
#
# 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

For the commits you want to squash, change the action to squash (or other actions you want to perform). save and close editor for changes to be applied.

Upvotes: 2

Related Questions