git-merge --squash

Some people tend to do many little commits on a topic branch,
recording all the trials and errors, and when the topic is
reasonably cooked well, would want to record the net effect of
the series as one commit on top of the mainline, removing the
cruft from the history.  The topic is then abandoned or forked
off again from that point at the mainline.

The barebone porcelainish that comes with core git tools does
not officially support such operation, but you can fake it by
using "git pull --no-merge" when such a topic branch is not a
strict superset of the mainline, like this:

	git checkout mainline
	git pull --no-commit . that-topic-branch
	: fix conflicts if any
	rm -f .git/MERGE_HEAD
        git commit -a -m 'consolidated commit log message'
	git branch -f that-topic-branch ;# now fully merged

This however does not work when the topic branch is a fast
forward of the mainline, because normal "git pull" will never
create a merge commit in such a case, and there is nothing
special --no-commit could do to begin with.

This patch introduces a new option, --squash, to support such a
workflow officially in both fast-forward case and true merge
case.  The user-level operation would be the same in both cases:

	git checkout mainline
        git pull --squash . that-topic-branch
        : fix conflicts if any -- naturally, there would be
        : no conflict if fast forward.
	git commit -a -m  'consolidated commit log message'
	git branch -f that-topic-branch ;# now fully merged

When the current branch is already up-to-date with respect to
the other branch, there truly is nothing to do, so the new
option does not have any effect.

This was brought up in #git IRC channel recently.

Signed-off-by: Junio C Hamano <junkio@cox.net>
5 files changed
tree: db32675e5727f32319463071c6ae2ebba818a474
  1. arm/
  2. compat/
  3. contrib/
  4. Documentation/
  5. gitweb/
  6. mozilla-sha1/
  7. ppc/
  8. t/
  9. templates/
  10. xdiff/
  11. .gitignore
  12. alloc.c
  13. base85.c
  14. blame.c
  15. blob.c
  16. blob.h
  17. builtin-add.c
  18. builtin-apply.c
  19. builtin-cat-file.c
  20. builtin-check-ref-format.c
  21. builtin-commit-tree.c
  22. builtin-count.c
  23. builtin-diff-files.c
  24. builtin-diff-index.c
  25. builtin-diff-stages.c
  26. builtin-diff-tree.c
  27. builtin-diff.c
  28. builtin-grep.c
  29. builtin-help.c
  30. builtin-init-db.c
  31. builtin-log.c
  32. builtin-ls-files.c
  33. builtin-ls-tree.c
  34. builtin-mailinfo.c
  35. builtin-mailsplit.c
  36. builtin-push.c
  37. builtin-read-tree.c
  38. builtin-rev-list.c
  39. builtin-rev-parse.c
  40. builtin-rm.c
  41. builtin-show-branch.c
  42. builtin-stripspace.c
  43. builtin-tar-tree.c
  44. builtin-update-index.c
  45. builtin-update-ref.c
  46. builtin-upload-tar.c
  47. builtin-write-tree.c
  48. builtin.h
  49. cache-tree.c
  50. cache-tree.h
  51. cache.h
  52. checkout-index.c
  53. combine-diff.c
  54. commit.c
  55. commit.h
  56. config.c
  57. connect.c
  58. convert-objects.c
  59. copy.c
  60. COPYING
  61. csum-file.c
  62. csum-file.h
  63. ctype.c
  64. daemon.c
  65. date.c
  66. delta.h
  67. describe.c
  68. diff-delta.c
  69. diff-lib.c
  70. diff.c
  71. diff.h
  72. diffcore-break.c
  73. diffcore-delta.c
  74. diffcore-order.c
  75. diffcore-pickaxe.c
  76. diffcore-rename.c
  77. diffcore.h
  78. dir.c
  79. dir.h
  80. dump-cache-tree.c
  81. entry.c
  82. environment.c
  83. exec_cmd.c
  84. exec_cmd.h
  85. fetch-clone.c
  86. fetch-pack.c
  87. fetch.c
  88. fetch.h
  89. fsck-objects.c
  90. generate-cmdlist.sh
  91. git-am.sh
  92. git-annotate.perl
  93. git-applymbox.sh
  94. git-applypatch.sh
  95. git-archimport.perl
  96. git-bisect.sh
  97. git-branch.sh
  98. git-checkout.sh
  99. git-cherry.sh
  100. git-clean.sh
  101. git-clone.sh
  102. git-commit.sh
  103. git-compat-util.h
  104. git-cvsexportcommit.perl
  105. git-cvsimport.perl
  106. git-cvsserver.perl
  107. git-fetch.sh
  108. git-fmt-merge-msg.perl
  109. git-lost-found.sh
  110. git-ls-remote.sh
  111. git-merge-octopus.sh
  112. git-merge-one-file.sh
  113. git-merge-ours.sh
  114. git-merge-recursive.py
  115. git-merge-resolve.sh
  116. git-merge-stupid.sh
  117. git-merge.sh
  118. git-mv.perl
  119. git-p4import.py
  120. git-parse-remote.sh
  121. git-prune.sh
  122. git-pull.sh
  123. git-push.sh
  124. git-quiltimport.sh
  125. git-rebase.sh
  126. git-relink.perl
  127. git-repack.sh
  128. git-request-pull.sh
  129. git-rerere.perl
  130. git-reset.sh
  131. git-resolve.sh
  132. git-revert.sh
  133. git-send-email.perl
  134. git-sh-setup.sh
  135. git-shortlog.perl
  136. git-svnimport.perl
  137. git-tag.sh
  138. git-verify-tag.sh
  139. GIT-VERSION-GEN
  140. git.c
  141. git.spec.in
  142. gitk
  143. gitMergeCommon.py
  144. hash-object.c
  145. http-fetch.c
  146. http-push.c
  147. http.c
  148. http.h
  149. ident.c
  150. imap-send.c
  151. index-pack.c
  152. INSTALL
  153. local-fetch.c
  154. lockfile.c
  155. log-tree.c
  156. log-tree.h
  157. Makefile
  158. merge-base.c
  159. merge-index.c
  160. merge-tree.c
  161. mktag.c
  162. mktree.c
  163. name-rev.c
  164. object-refs.c
  165. object.c
  166. object.h
  167. pack-check.c
  168. pack-objects.c
  169. pack-redundant.c
  170. pack.h
  171. pager.c
  172. patch-delta.c
  173. patch-id.c
  174. path.c
  175. peek-remote.c
  176. pkt-line.c
  177. pkt-line.h
  178. prune-packed.c
  179. quote.c
  180. quote.h
  181. read-cache.c
  182. README
  183. receive-pack.c
  184. refs.c
  185. refs.h
  186. repo-config.c
  187. revision.c
  188. revision.h
  189. rsh.c
  190. rsh.h
  191. run-command.c
  192. run-command.h
  193. send-pack.c
  194. server-info.c
  195. setup.c
  196. sha1_file.c
  197. sha1_name.c
  198. shell.c
  199. show-index.c
  200. ssh-fetch.c
  201. ssh-pull.c
  202. ssh-push.c
  203. ssh-upload.c
  204. strbuf.c
  205. strbuf.h
  206. symbolic-ref.c
  207. tag.c
  208. tag.h
  209. tar.h
  210. test-date.c
  211. test-delta.c
  212. tree-diff.c
  213. tree-walk.c
  214. tree-walk.h
  215. tree.c
  216. tree.h
  217. unpack-file.c
  218. unpack-objects.c
  219. update-server-info.c
  220. upload-pack.c
  221. usage.c
  222. var.c
  223. verify-pack.c
  224. xdiff-interface.c
  225. xdiff-interface.h