dczajkowski
dczajkowski

Reputation: 172

Squash commits before hash

I have forked a quick-start repo and built an app on top of it. The quick-start repo contained ~30 commits. The last commit of their repo is, say, abcde and first commit of mine is, say, fghij. How can I squash all of the commits, from first to abcde, so that there is only one, big commit before fghij.

Could you please explain it line by line. I don't understand other answers under similar topics.

Example history tree of commits now:

klmno - Currently newest commit
.
.
.
fghij - Initial commit of mine
abcde - Last commit made by them
.
.
vwxyz - Initial commit of theirs

Example history tree of commits expected:

klmno - Currently newest commit
.
.
.
fghij - Initial commit of mine
prstu - Fresh X installation

Upvotes: 2

Views: 392

Answers (1)

Robin Green
Robin Green

Reputation: 33063

First enter git's interactive rebase mode - note that in this special case, you have to specify the special option --root to edit the root (first) commit, which is usually not allowed with the git rebase command:

git rebase -i --root

If you have not configured the EDITOR environment variable, you will be taken into git's default text editor, which I think is always vi. If you don't understand vi, type :q to exit and start the process again - this time, setting EDITOR to the name of a text editor you do know how to use.

In the interactive rebase file that git gives you to edit, change all the lines for the commits from the second commit to abcde to start with the word fixup instead of pick. Leave the lines for your commits, and the line for the very first commit, unchanged.

Save the file and exit the text editor. git will now perform the squashing of the original repository's commits into one commit.

Upvotes: 1

Related Questions