Confirmed users
425
edits
Line 56: | Line 56: | ||
=== Using interactive rebase to squash commits === | === Using interactive rebase to squash commits === | ||
You will use | You will use git's interactive rebase feature to take all of the commits that are currently in the branch and ''squash'' them into a single commit. | ||
''Note:'' If all the commits are ones that were added only to the feature branch then you should not run into any issues. If your feature branch includes commits from master that were pulled in during development of the feature, you could encounter conflicts when doing the interactive rebase which you'll need to address. In this case it might be simpler to go with the second option ''merge with --squash''. | ''Note:'' If all the commits are ones that were added only to the feature branch then you should not run into any issues. If your feature branch includes commits from master that were pulled in during development of the feature, you could encounter conflicts when doing the interactive rebase which you'll need to address. In this case it might be simpler to go with the second option ''merge with --squash''. | ||
Line 64: | Line 64: | ||
* Start up an interactive rebase session to squash all of the commits in the feature branch that are not currently in the ''master'' branch: | * Start up an interactive rebase session to squash all of the commits in the feature branch that are not currently in the ''master'' branch: | ||
** <code>git rebase -i master</code> | ** <code>git rebase -i master</code> | ||
* This will pop open a code editor ( | * This will pop open a code editor (whichever one is configured to be used with git) with a file that includes some rebasing instructions. The file will look something like this: | ||
[[File:Git-rebase-1.jpg|545 × 414 px]] | [[File:Git-rebase-1.jpg|545 × 414 px]] | ||
* This is convenient as | * This is convenient as git provides you with some instructions. We want to combine the second and third commit with the first, so in this example we would edit the file to look like this: | ||
[[File:Git-rebase-2.jpg]] | [[File:Git-rebase-2.jpg]] | ||
* Note that you can just type an <code>s</code> instead of the whole word <code>squash</code>. | |||
* When you save and close the file git will pop open another file in the editor to edit the commit message: |