Confirmed users
425
edits
Line 65: | Line 65: | ||
** <code>git rebase -i master</code> | ** <code>git rebase -i master</code> | ||
* 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: | * 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 | [[File:Git-rebase-1.jpg]] | ||
* This is convenient as git provides you with some instructions. | * This is convenient as git provides you with some instructions. In this example, you want to combine the second and third commit with the first, so you 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>. | * 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: | * When you save and close the file git will pop open another file in the editor to edit the commit message: | ||
[[File:Git-rebase-3.jpg]] | |||
* From here you can either choose to accept the three individual commit messages that were picked up from the three commits, or you can remove them (or comment them out) and provide your own commit message. When you save and close this file you'll be back at the command line with a message similar to this: | |||
** <code>Successfully rebased and updated refs/heads/my_branch.</code> | |||
* If you have done this for your own pull request you can now push the new commit to your branch, forcing the new commit to overwrite any previous commits: | |||
** <code>git push -f origin my_branch</code> | |||
* If you are doing this on behalf of someone else, in order to squash their commits before merging, you can merge this new branch into your local master branch and then push the master branch: | |||
<code> | |||
git checkout master | |||
git pull upstream master | |||
git merge my_branch | |||
git push upstream master | |||
</code> |