-
-
Notifications
You must be signed in to change notification settings - Fork 459
Merge commits in pull requests
It is good practice that every time that you do a pull request, the commit history contains the minimum necessary commit messages.
If you have worked locally on some feature, and produced a lot of commits in the process to reach to the final state, the rest of the world does not necessarily need to know your intermediate back and forth activity. You may just want to merge all these commits into a single one, and provide a nice summary of the changes that the changes introduce.
In order to do squash your own commits you can use GIT_EDITOR= git rebase -i , where is the editor of your choice (nano, vim, gedit) and is the commit from which you want to start the review.
Example:
GIT_EDITOR=gedit git rebase -i 1949129
This produces:
pick 1949129 Introduce feature A
pick d2cf643 Fix bug 1 of feature A
pick 42bd9e8 Fix bug 2 of feature A
pick 7f767d5 Fix bug 3 of feature A
You want a single commit with one description only. Then change the lines to:
pick 1949129 Introduce feature A
fixup d2cf643 Fix bug 1 of feature A
fixup 42bd9e8 Fix bug 2 of feature A
fixup 7f767d5 Fix bug 3 of feature A
This produces the following result:
1949129 Introduce feature A
Suppose that you have commited your changes, and then in the future you introduce new features to your module. But in the meanwhile Transifex has produced several commits in the middle that make the commit history look dirty. You can merge all commits from Transifex together.
In order to do squash the commits from Transifex for a particular module, use:
GIT_EDITOR= git rebase -i origin/x, where x is the Odoo version (8, 9, 10,...)
Example: You introduce commit:
d2cf643 Improve feature A, version 2 to an existing code. But looking at the PR you see plenty of commits from 'OCA Transbot'. You want to merge them together.
GIT_EDITOR=gedit git rebase -i origin/9.0
This produces:
pick 1949129 Introduce feature A
pick 00b6571 OCA Transbot updated translations from Transifex
pick 3ee02e5 OCA Transbot updated translations from Transifex
pick 3296788 Improve feature A
pick 42bd9e8 OCA Transbot updated translations from Transifex
pick d2cf643 Improve feature A, version 2
You can then reorder the lines of OCA Transbot together, and put them in the end, respecting the relative order of the OCA Transbot commits. After rearranging the transifex commits you have to add fixup to the commits except the first one, so to squash all the below commits of transifex to the top one.
pick 1949129 Introduce feature A
pick 3296788 Improve feature A
pick d2cf643 Improve feature A, version 2
pick 00b6571 OCA Transbot updated translations from Transifex
fixup 3ee02e5 OCA Transbot updated translations from Transifex
fixup 42bd9e8 OCA Transbot updated translations from Transifex
This would simplify the commit history, resulting in:
1949129 Introduce feature A
3296788 Improve feature A
d2cf643 Improve feature A, version 2
00b6571 OCA Transbot updated translations from Transifex