Knowledge Base
Authentication is disabled (development mode).

git rebase branch to squashed copy of that branch

Edit

branch commit different git merge rebase squash squashed

Preparing a repository with 10 commits

mkdir repo
cd repo/

git init

for n in {0..9}
do
 date +'%FT%T.%N%z' >> file
 git add file
 git commit -m "#$n"
done

git log --oneline

	1f663b1 (HEAD -> master) #9
	d4ddb93 #8
	11f31f6 #7
	ac46d1b #6
	26fef4e #5
	c313998 #4
	d32b779 #3
	9fbe5d8 #2
	619fd44 #1
	5e9d7ea #0

Squashing commits in a different branch
(like this:)

git checkout -b branch

# The below sequence.editor script is equal to:
	p 619fd44 #1
	s 9fbe5d8 #2
	s d32b779 #3
	s c313998 #4
	p 26fef4e #5
	s ac46d1b #6
	p 11f31f6 #7
	p d4ddb93 #8
	s 1f663b1 #9

git -c core.editor='sed -i "1s/# *//g; s/^#[0-9]/ &/g; /^$/d"' -c sequence.editor='sed -i "2,4s/^pick/s/g; 6s/^pick/s/g; 9s/^pick/s/g;"' rebase -i HEAD~9

	[detached HEAD fa9a75c] This is a combination of 4 commits.  #1  #2  #3  #4
	 1 file changed, 4 insertions(+)
	[detached HEAD 6915943] This is a combination of 2 commits.  #5  #6
	 1 file changed, 2 insertions(+)
	[detached HEAD a78dae6] This is a combination of 2 commits.  #8  #9
	 1 file changed, 2 insertions(+)
	Successfully rebased and updated refs/heads/branch.

git log --oneline

	a78dae6 (HEAD -> branch) This is a combination of 2 commits.  #8  #9
	af0bb1c #7
	6915943 This is a combination of 2 commits.  #5  #6
	fa9a75c This is a combination of 4 commits.  #1  #2  #3  #4
	5e9d7ea #0

Apply squashed commits after reverting to first common commit

git checkout master
git reset HEAD~9
git checkout .
git rebase branch