If you are sure that you want only one commit and excellent with a branch that will never be marked as "merged" (perhaps because you are going to delete it with git branch -D my-squash-merged-branch and no longer want see her), use this:
git checkout master git merge --squash branch-to-merge git commit -m "message for commit"
However, after much testing, I find the best way to merge most branches:
git checkout master git merge --no-ff branch-to-merge -m "message for commit"
This avoids the fast-forward merge, which prohibits the -m "message" option for many merges. In fact, it does not provide a separate commit, as originally requested, but at least makes it easy to see the beginning / end of a branch and thus simplifies the return process, etc. A git log display all the individual commits that have been merged ...
commit a6672a4c3d90c35d5f39c45f307ef6b385660196 Merge: 015f8d6 f84e029 Author: Brian White <bcwhite@example.com> Date: Wed Jan 15 20:47:35 2014 -0500 merged something trivial commit f84e02915faa02afc9a31b8c93a6e7712420687d Author: Brian White <bcwhite@example.com> Date: Wed Jan 15 20:47:12 2014 -0500 added something also trivial commit 904d5b5ff00d691d63104a77d2e2ca484732a5fb Author: Brian White <bcwhite@example.com> Date: Wed Jan 15 20:46:26 2014 -0500 added something trivial commit 015f8d681bdaf65725067ee8058215cedb529dd6 Author: Brian White <bcwhite@example.com> Date: Wed Jan 15 20:23:31 2014 -0500 optimizations to MyThing ...
... but if you look at the log graph ( git log --graph ), you will see that git does recognize it as a single merge.
* commit a6672a4c3d90c35d5f39c45f307ef6b385660196 |\ Merge: 015f8d6 f84e029 | | Author: Brian White <bcwhite@example.com> | | Date: Wed Jan 15 20:47:35 2014 -0500 | | | | merged something trivial | | | * commit f84e02915faa02afc9a31b8c93a6e7712420687d | | Author: Brian White <bcwhite@example.com> | | Date: Wed Jan 15 20:47:12 2014 -0500 | | | | added something also trivial | | | * commit 904d5b5ff00d691d63104a77d2e2ca484732a5fb |/ Author: Brian White <bcwhite@example.com> | Date: Wed Jan 15 20:46:26 2014 -0500 | | added something trivial | * commit 015f8d681bdaf65725067ee8058215cedb529dd6 | Author: Brian White <bcwhite@example.com> | Date: Wed Jan 15 20:23:31 2014 -0500 | | optimizations to MyThing ...
If commits or other actions occur on the main branch, the combined branch will be displayed on the chart, starting from the right place and connecting to the current head, but, of course, all commits will still be displayed in the log with the commit from the branch being at the top.
Brian White Jan 16 '14 at 2:23 2014-01-16 02:23
source share