history: add squash subcommand to fold a range

Folding a series of commits into one required either an interactive
rebase where each commit after the first was hand-edited to "fixup", or
a "git reset --soft" to the merge base followed by "git commit --amend".

Add "git history squash <revision-range>" to do this directly. It folds
every commit in the range into the oldest one, keeping that commit's
authorship and taking the tree of the newest commit, then replays the
commits above the range on top. The squashed message comes from the
oldest commit by default, or from the body of the last amend! commit
targeting it. An editor opens with the selected message when
--reedit-message is given. A fixup!, squash! or amend! commit is refused
unless the commit it targets is also in the range, so the fold does not
silently absorb a marker meant for a commit outside it. The check runs
the range through todo_list_rearrange_squash(), which leaves such a
marker as a plain pick. Markers whose target is in the range fold in as
usual. As an exception, a range made up entirely of markers for one
target is combined anyway, taking its message from the last amend! if
there is one, so a batch of fixups for the same commit can be collapsed.

The range is read like the arguments to "git rev-list", so several
revisions such as "HEAD~3..HEAD ^topic" may be given, and rev-list
options are accepted too. As "git replay" does, the walk options the fold
relies on are forced after setup_revisions() and a warning is printed if
an option changed them, so the first commit returned is the range's
oldest and its parent is the base regardless of what the user passed
(including after a "--"). A merge inside the range is folded when its
other parent is reachable from the base, otherwise the range has more
than one base and is rejected. By default the command also refuses when a
ref points at a commit that the fold would discard. Use --update-refs=head
to rewrite only the current branch instead.

Inspired-by: Sergey Chernov <serega.morph@gmail.com>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
7 files changed
tree: ea0e1b62b30a00aab77d50f47ea3fa28286ffa98
  1. .github/
  2. bin-wrappers/
  3. block-sha1/
  4. builtin/
  5. ci/
  6. compat/
  7. compiler-tricks/
  8. contrib/
  9. Documentation/
  10. ewah/
  11. git-gui/
  12. gitk-git/
  13. gitweb/
  14. mergetools/
  15. negotiator/
  16. odb/
  17. oss-fuzz/
  18. perl/
  19. po/
  20. refs/
  21. reftable/
  22. sha1/
  23. sha1dc/
  24. sha256/
  25. src/
  26. subprojects/
  27. t/
  28. templates/
  29. tools/
  30. trace2/
  31. xdiff/
  32. .b4-config
  33. .b4-cover-template
  34. .cirrus.yml
  35. .clang-format
  36. .editorconfig
  37. .gitattributes
  38. .gitignore
  39. .gitlab-ci.yml
  40. .gitmodules
  41. .mailmap
  42. .tsan-suppressions
  43. abspath.c
  44. abspath.h
  45. aclocal.m4
  46. add-interactive.c
  47. add-interactive.h
  48. add-patch.c
  49. add-patch.h
  50. advice.c
  51. advice.h
  52. alias.c
  53. alias.h
  54. alloc.c
  55. alloc.h
  56. apply.c
  57. apply.h
  58. archive-tar.c
  59. archive-zip.c
  60. archive.c
  61. archive.h
  62. attr.c
  63. attr.h
  64. banned.h
  65. base85.c
  66. base85.h
  67. bisect.c
  68. bisect.h
  69. blame.c
  70. blame.h
  71. blob.c
  72. blob.h
  73. bloom.c
  74. bloom.h
  75. branch.c
  76. branch.h
  77. build.rs
  78. builtin.h
  79. bundle-uri.c
  80. bundle-uri.h
  81. bundle.c
  82. bundle.h
  83. cache-tree.c
  84. cache-tree.h
  85. Cargo.toml
  86. cbtree.c
  87. cbtree.h
  88. chdir-notify.c
  89. chdir-notify.h
  90. checkout.c
  91. checkout.h
  92. chunk-format.c
  93. chunk-format.h
  94. CODE_OF_CONDUCT.md
  95. color.c
  96. color.h
  97. column.c
  98. column.h
  99. combine-diff.c
  100. command-list.txt
  101. commit-graph.c
  102. commit-graph.h
  103. commit-reach.c
  104. commit-reach.h
  105. commit-slab-decl.h
  106. commit-slab-impl.h
  107. commit-slab.h
  108. commit.c
  109. commit.h
  110. common-exit.c
  111. common-init.c
  112. common-init.h
  113. common-main.c
  114. config.c
  115. config.h
  116. config.mak.dev
  117. config.mak.in
  118. config.mak.uname
  119. configure.ac
  120. connect.c
  121. connect.h
  122. connected.c
  123. connected.h
  124. convert.c
  125. convert.h
  126. copy.c
  127. copy.h
  128. COPYING
  129. credential.c
  130. credential.h
  131. csum-file.c
  132. csum-file.h
  133. ctype.c
  134. daemon.c
  135. date.c
  136. date.h
  137. decorate.c
  138. decorate.h
  139. delta-islands.c
  140. delta-islands.h
  141. delta.h
  142. diagnose.c
  143. diagnose.h
  144. diff-delta.c
  145. diff-lib.c
  146. diff-merges.c
  147. diff-merges.h
  148. diff-no-index.c
  149. diff.c
  150. diff.h
  151. diffcore-break.c
  152. diffcore-delta.c
  153. diffcore-order.c
  154. diffcore-pickaxe.c
  155. diffcore-rename.c
  156. diffcore-rotate.c
  157. diffcore.h
  158. dir-iterator.c
  159. dir-iterator.h
  160. dir.c
  161. dir.h
  162. editor.c
  163. editor.h
  164. entry.c
  165. entry.h
  166. environment.c
  167. environment.h
  168. exec-cmd.c
  169. exec-cmd.h
  170. fetch-negotiator.c
  171. fetch-negotiator.h
  172. fetch-pack.c
  173. fetch-pack.h
  174. fmt-merge-msg.c
  175. fmt-merge-msg.h
  176. for-each-ref.h
  177. fsck.c
  178. fsck.h
  179. fsmonitor--daemon.h
  180. fsmonitor-ipc.c
  181. fsmonitor-ipc.h
  182. fsmonitor-ll.h
  183. fsmonitor-path-utils.h
  184. fsmonitor-settings.c
  185. fsmonitor-settings.h
  186. fsmonitor.c
  187. fsmonitor.h
  188. gettext.c
  189. gettext.h
  190. git-archimport.perl
  191. GIT-BUILD-OPTIONS.in
  192. git-compat-util.h
  193. git-curl-compat.h
  194. git-cvsexportcommit.perl
  195. git-cvsimport.perl
  196. git-cvsserver.perl
  197. git-difftool--helper.sh
  198. git-filter-branch.sh
  199. git-instaweb.sh
  200. git-merge-octopus.sh
  201. git-merge-one-file.sh
  202. git-merge-resolve.sh
  203. git-mergetool--lib.sh
  204. git-mergetool.sh
  205. git-p4.py
  206. git-quiltimport.sh
  207. git-request-pull.sh
  208. git-send-email.perl
  209. git-sh-i18n.sh
  210. git-sh-setup.sh
  211. git-submodule.sh
  212. git-svn.perl
  213. GIT-VERSION-FILE.in
  214. GIT-VERSION-GEN
  215. git-web--browse.sh
  216. git-zlib.c
  217. git-zlib.h
  218. git.c
  219. git.rc.in
  220. gpg-interface.c
  221. gpg-interface.h
  222. graph.c
  223. graph.h
  224. grep.c
  225. grep.h
  226. hash-lookup.c
  227. hash-lookup.h
  228. hash.c
  229. hash.h
  230. hashmap.c
  231. hashmap.h
  232. help.c
  233. help.h
  234. hex-ll.c
  235. hex-ll.h
  236. hex.c
  237. hex.h
  238. hook.c
  239. hook.h
  240. http-backend.c
  241. http-fetch.c
  242. http-push.c
  243. http-walker.c
  244. http.c
  245. http.h
  246. ident.c
  247. ident.h
  248. imap-send.c
  249. INSTALL
  250. iterator.h
  251. json-writer.c
  252. json-writer.h
  253. khash.h
  254. kwset.c
  255. kwset.h
  256. levenshtein.c
  257. levenshtein.h
  258. LGPL-2.1
  259. line-log.c
  260. line-log.h
  261. line-range.c
  262. line-range.h
  263. linear-assignment.c
  264. linear-assignment.h
  265. list-objects-filter-options.c
  266. list-objects-filter-options.h
  267. list-objects-filter.c
  268. list-objects-filter.h
  269. list-objects.c
  270. list-objects.h
  271. list.h
  272. lockfile.c
  273. lockfile.h
  274. log-tree.c
  275. log-tree.h
  276. loose.c
  277. loose.h
  278. ls-refs.c
  279. ls-refs.h
  280. mailinfo.c
  281. mailinfo.h
  282. mailmap.c
  283. mailmap.h
  284. Makefile
  285. match-trees.c
  286. match-trees.h
  287. mem-pool.c
  288. mem-pool.h
  289. merge-blobs.c
  290. merge-blobs.h
  291. merge-ll.c
  292. merge-ll.h
  293. merge-ort-wrappers.c
  294. merge-ort-wrappers.h
  295. merge-ort.c
  296. merge-ort.h
  297. merge.c
  298. merge.h
  299. mergesort.h
  300. meson.build
  301. meson_options.txt
  302. midx-write.c
  303. midx.c
  304. midx.h
  305. name-hash.c
  306. name-hash.h
  307. notes-cache.c
  308. notes-cache.h
  309. notes-merge.c
  310. notes-merge.h
  311. notes-utils.c
  312. notes-utils.h
  313. notes.c
  314. notes.h
  315. object-file-convert.c
  316. object-file-convert.h
  317. object-file.c
  318. object-file.h
  319. object-name.c
  320. object-name.h
  321. object.c
  322. object.h
  323. odb.c
  324. odb.h
  325. oid-array.c
  326. oid-array.h
  327. oidmap.c
  328. oidmap.h
  329. oidset.c
  330. oidset.h
  331. oidtree.c
  332. oidtree.h
  333. pack-bitmap-write.c
  334. pack-bitmap.c
  335. pack-bitmap.h
  336. pack-check.c
  337. pack-mtimes.c
  338. pack-mtimes.h
  339. pack-objects.c
  340. pack-objects.h
  341. pack-refs.c
  342. pack-refs.h
  343. pack-revindex.c
  344. pack-revindex.h
  345. pack-write.c
  346. pack.h
  347. packfile-list.c
  348. packfile-list.h
  349. packfile.c
  350. packfile.h
  351. pager.c
  352. pager.h
  353. parallel-checkout.c
  354. parallel-checkout.h
  355. parse-options-cb.c
  356. parse-options.c
  357. parse-options.h
  358. parse.c
  359. parse.h
  360. patch-delta.c
  361. patch-ids.c
  362. patch-ids.h
  363. path-walk.c
  364. path-walk.h
  365. path.c
  366. path.h
  367. pathspec.c
  368. pathspec.h
  369. pkt-line.c
  370. pkt-line.h
  371. preload-index.c
  372. preload-index.h
  373. pretty.c
  374. pretty.h
  375. prio-queue.c
  376. prio-queue.h
  377. progress.c
  378. progress.h
  379. promisor-remote.c
  380. promisor-remote.h
  381. prompt.c
  382. prompt.h
  383. protocol-caps.c
  384. protocol-caps.h
  385. protocol.c
  386. protocol.h
  387. prune-packed.c
  388. prune-packed.h
  389. pseudo-merge.c
  390. pseudo-merge.h
  391. quote.c
  392. quote.h
  393. range-diff.c
  394. range-diff.h
  395. reachable.c
  396. reachable.h
  397. read-cache-ll.h
  398. read-cache.c
  399. read-cache.h
  400. README.md
  401. rebase-interactive.c
  402. rebase-interactive.h
  403. rebase.c
  404. rebase.h
  405. ref-filter.c
  406. ref-filter.h
  407. reflog-walk.c
  408. reflog-walk.h
  409. reflog.c
  410. reflog.h
  411. refs.c
  412. refs.h
  413. refspec.c
  414. refspec.h
  415. remote-curl.c
  416. remote.c
  417. remote.h
  418. repack-cruft.c
  419. repack-filtered.c
  420. repack-geometry.c
  421. repack-midx.c
  422. repack-promisor.c
  423. repack.c
  424. repack.h
  425. replace-object.c
  426. replace-object.h
  427. replay.c
  428. replay.h
  429. repo-settings.c
  430. repo-settings.h
  431. repository.c
  432. repository.h
  433. rerere.c
  434. rerere.h
  435. reset.c
  436. reset.h
  437. resolve-undo.c
  438. resolve-undo.h
  439. revision.c
  440. revision.h
  441. run-command.c
  442. run-command.h
  443. sane-ctype.h
  444. scalar.c
  445. SECURITY.md
  446. send-pack.c
  447. send-pack.h
  448. sequencer.c
  449. sequencer.h
  450. serve.c
  451. serve.h
  452. server-info.c
  453. server-info.h
  454. setup.c
  455. setup.h
  456. sh-i18n--envsubst.c
  457. sha1dc_git.c
  458. sha1dc_git.h
  459. shallow.c
  460. shallow.h
  461. shared.mak
  462. shell.c
  463. shortlog.h
  464. sideband.c
  465. sideband.h
  466. sigchain.c
  467. sigchain.h
  468. simple-ipc.h
  469. sparse-index.c
  470. sparse-index.h
  471. split-index.c
  472. split-index.h
  473. stable-qsort.c
  474. statinfo.c
  475. statinfo.h
  476. strbuf.c
  477. strbuf.h
  478. string-list.c
  479. string-list.h
  480. strmap.c
  481. strmap.h
  482. strvec.c
  483. strvec.h
  484. sub-process.c
  485. sub-process.h
  486. submodule-config.c
  487. submodule-config.h
  488. submodule.c
  489. submodule.h
  490. symlinks.c
  491. symlinks.h
  492. tag.c
  493. tag.h
  494. tar.h
  495. tempfile.c
  496. tempfile.h
  497. thread-utils.c
  498. thread-utils.h
  499. tmp-objdir.c
  500. tmp-objdir.h
  501. trace.c
  502. trace.h
  503. trace2.c
  504. trace2.h
  505. trailer.c
  506. trailer.h
  507. transport-helper.c
  508. transport-internal.h
  509. transport.c
  510. transport.h
  511. tree-diff.c
  512. tree-walk.c
  513. tree-walk.h
  514. tree.c
  515. tree.h
  516. unicode-width.h
  517. unimplemented.sh
  518. unix-socket.c
  519. unix-socket.h
  520. unix-stream-server.c
  521. unix-stream-server.h
  522. unpack-trees.c
  523. unpack-trees.h
  524. upload-pack.c
  525. upload-pack.h
  526. url.c
  527. url.h
  528. urlmatch.c
  529. urlmatch.h
  530. usage.c
  531. userdiff.c
  532. userdiff.h
  533. utf8.c
  534. utf8.h
  535. varint.c
  536. varint.h
  537. version-def.h.in
  538. version.c
  539. version.h
  540. versioncmp.c
  541. versioncmp.h
  542. walker.c
  543. walker.h
  544. wildmatch.c
  545. wildmatch.h
  546. worktree.c
  547. worktree.h
  548. wrapper.c
  549. wrapper.h
  550. write-or-die.c
  551. write-or-die.h
  552. ws.c
  553. ws.h
  554. wt-status.c
  555. wt-status.h
  556. xdiff-interface.c
  557. xdiff-interface.h
README.md

GitHub build status GitLab build status

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.adoc to get started, then see Documentation/giteveryday.adoc for a useful minimum set of commands, and Documentation/git-<commandname>.adoc for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.adoc (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission and Documentation/CodingGuidelines).

Those wishing to help with error message, usage and informational message string translations (localization l10) should see po/README.md (a po file is a Portable Object file that holds the translations).

To subscribe to the list, send an email to git+subscribe@vger.kernel.org (see https://subspace.kernel.org/subscribing.html for details). The mailing list archives are available at https://lore.kernel.org/git/, https://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks