forked from Baystation12/Baystation12
-
Notifications
You must be signed in to change notification settings - Fork 28
Squashing
Sabira edited this page Oct 26, 2018
·
2 revisions
Squashing is the processing of combining several commits into a single resultant commit. This is done to keep the commit history clean. I'll only explain how to do this via the command line since it's just punching in commands. You'll need a command line open pointed at your repository (use the cd
command in Windows to move through directories, or open it via the File menu)
There are several ways to squash, so a few different methods will be covered.
- First, you need to know how many commits you want to squash. Usually, you'll be able to look at the open pull request and it will tell you know many commits you have.
- After you know how many commits you want to squash, enter the command
git rebase -i HEAD~#
where#
is the number of commits you want to squash. You'll then get something that looks like this in your text editor:
- The commands tell you what you can do. For our purposes, we want to set 222222, 3333333 and 444444 to squash, and 1111111 to pick. After you've done that, save and close the editor.
- After that, you'll get another text editor to allow you to modify the newly squashed commit message. Save and close the editor once you're finished.
- After you've squashed, you'll need to force push the changes up to your repo. Keep in mind that force push will overwrite all commits on this branch, which is what we need it to do in this case. In your command line, enter
git push FORK BRANCH --force
whereFORK
is the name of your personal repository (it will be 'fork', if you set up git according to the guides contained here) andBRANCH
is the name of the branch.
- Open your command line pointed at your repository, and switch to the dev branch and ensure it's up to date:
git checkout dev
thengit pull
- Now enter
git merge BRANCH
whereBRANCH
is the name of the branch you want to squash - Enter
git reset origin/dev
, which will reset yourdev
branch to the main repository's version. - You can now add your files to commit using either the command line (
git commit -a
) or your client of choice. - You'll need to force push; refer to the final point in the guide above.
Documentation regarding setting up and using Git.
Making heads or tails of specific GitHub pages, for the uninitiated.
Documentation regarding tools external to DM and Git.
Standards and guidelines regarding commenting, contributor conduct and coding standards.