This is exactly the way I usually follow to combine multiple commits into one commit before pushing the code.
To achieve this, I suggest you use the squash concept provided by GIT.
Follow these steps.
1) git rebase -i wizard ( you can also use a specific commit instead of a wizard )
open the rebase interactive editor where it will show all your commits. Basically, where you need to identify the commits that you want to merge into a single commit.
Imagine that these are your commits and something similar is shown in the editor.
pick f7f3f6d changed my name a bit pick 310154e updated README formatting and added blame pick a5f4a0d added cat-file
It is important to note that these commits are listed in reverse order than you usually see them with the log command. So the old commit will be shown first.
2) Change 'pick' to 'squash' for the latest committed changes. something like shown below. At the same time, your last 2 commits will be merged with the first.
pick f7f3f6d changed my name a bit squash 310154e updated README formatting and added blame squash a5f4a0d added cat-file
You can also use a short form if you have many commits to combine:
p f7f3f6d changed my name a bit s 310154e updated README formatting and added blame s a5f4a0d added cat-file
use 'i' for editing, it will enable the editor to insert. Keep in mind that most of the (oldest) commits cannot be crushed, since there is no previous commit that could be merged with. So this should be selected or "p". Use "Esc" to exit insert mode.
3) Now save the editor using the following command. : WQ
When you save this, you have one commit that represents the changes of all three previous commits.
Hope this helps you.
Kondal Kolipaka Nov 28 '12 at 11:58 2012-11-28 11:58
source share