Confirmed users
425
edits
No edit summary |
|||
Line 83: | Line 83: | ||
=== Using merge with --squash to squash commits === | === Using merge with --squash to squash commits === | ||
This method is a bit simpler than the above, but it requires an extra step which can be prone to user error. This is because when you do a ''merge with --squash'', you lose the author information, so you need to know what those values need to be and then update them afterwards. Here's an example. | |||
If we have a feature branch called <code>my_branch</code> and want to merge it into master and squash the commits, we would do the following: | |||
* Switch to the <code>master</code> branch: <code>git checkout master</code> | |||
* Merge the feature branch: <code>git merge my_branch --squash</code> | |||
* This will bring the changes in, but not commit them, so you need to do that: <code>git commit</code> | |||
** This will open your editor to specify the commit message, and it will be pre-populated with information from each commit in the feature branch. You can use some of these commit messages, or you can create your own. Make a note of the ''author'' specified in this file as you will need to use that value to update the author. | |||
* After you save the file you will be returned to the command line and the new commit will be added to the repo. | |||
* Now you need to update the author of this new commit to give ownership back to the original author (because you will currently be recorded as the author): <code>git commit --amend --author='exact_author_from_the_previous_commits'</code> | |||
** This will open your code editor one last time, which will allow you to edit the commit message again, but you won't need to change it as you will have already edited it in the step before, so just save and close the file. | |||
* As you are likely doing this in order to squash commits on behalf of someone else before merging, you can now push your local master branch to the main repo in order to merge the changes: <code>git push upstream master</code> |