'\" t .\" Title: git-history .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 2026-06-29 .\" Manual: Git Manual .\" Source: Git 2.55.0 .\" Language: English .\" .TH "GIT\-HISTORY" "1" "2026\-06\-29" "Git 2\&.55\&.0" "Git Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" git-history \- EXPERIMENTAL: Rewrite history .SH "SYNOPSIS" .sp .nf \fBgit\fR \fBhistory\fR \fBfixup\fR \fI\fR [\fB\-\-dry\-run\fR] [\fB\-\-update\-refs=\fR(\fBbranches\fR|\fBhead\fR)] [\fB\-\-reedit\-message\fR] [\fB\-\-empty=\fR(\fBdrop\fR|\fBkeep\fR|\fBabort\fR)] \fBgit\fR \fBhistory\fR \fBreword\fR \fI\fR [\fB\-\-dry\-run\fR] [\fB\-\-update\-refs=\fR(\fBbranches\fR|\fBhead\fR)] \fBgit\fR \fBhistory\fR \fBsplit\fR \fI\fR [\fB\-\-dry\-run\fR] [\fB\-\-update\-refs=\fR(\fBbranches\fR|\fBhead\fR)] [\fB\-\-\fR] [\fI\fR\&...] .fi .sp .SH "DESCRIPTION" .sp Rewrite history by rearranging or modifying specific commits in the history\&. .sp THIS COMMAND IS EXPERIMENTAL\&. THE BEHAVIOR MAY CHANGE\&. .sp This command is related to \fBgit-rebase\fR(1) in that both commands can be used to rewrite history\&. There are a couple of major differences though: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} Most subcommands of \fBgit-history\fR(1) can work in a bare repository as they do not need to touch either the index or the worktree\&. The \fBfixup\fR subcommand is an exception to this, as it reads staged changes from the index\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBgit-history\fR(1) does not execute any \fBgithooks\fR(5) at the current point in time\&. This may change in the future\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \fBgit-history\fR(1) by default updates all branches that are descendants of the original commit to point to the rewritten commit\&. .RE .sp Overall, \fBgit-history\fR(1) aims to provide a more opinionated way to modify your commit history that is simpler to use compared to \fBgit-rebase\fR(1) in general\&. .sp Use \fBgit-rebase\fR(1) if you want to reapply a range of commits onto a different base, or interactive rebases if you want to edit a range of commits at once\&. .SH "LIMITATIONS" .sp This command does not (yet) work with histories that contain merges\&. You should use \fBgit-rebase\fR(1) with the \fB\-\-rebase\-merges\fR flag instead\&. .sp Furthermore, the command does not support operations that can result in merge conflicts\&. This limitation is by design as history rewrites are not intended to be stateful operations\&. The limitation can be lifted once (if) Git learns about first\-class conflicts\&. .sp When using \fBfixup\fR with \fB\-\-empty=drop\fR, dropping the root commit is not yet supported\&. .SH "COMMANDS" .sp The following commands are available to rewrite history in different ways: .PP \fBfixup\fR \fI\fR .RS 4 Apply the currently staged changes to the specified commit\&. This is similar in nature to \fBgit\fR \fBcommit\fR \fB\-\-fixup=\fR\fI\fR followed by \fBgit\fR \fBrebase\fR \fB\-\-autosquash\fR \fI\fR\fB~\fR\&. Changes are applied to the target commit by performing a three\-way merge between the HEAD commit, the target commit and the tree generated from staged changes\&. .sp The commit message and authorship of the target commit are preserved by default, unless you specify \fB\-\-reedit\-message\fR\&. .sp If applying the staged changes would result in a conflict, the command aborts with an error\&. All branches that are descendants of the original commit are updated to point to the rewritten history\&. .RE .PP \fBreword\fR \fI\fR .RS 4 Rewrite the commit message of the specified commit\&. All the other details of this commit remain unchanged\&. This command will spawn an editor with the current message of that commit\&. .RE .PP \fBsplit\fR \fI\fR [\fB\-\-\fR] [\fI\fR\&.\&.\&.] .RS 4 Interactively split up into two commits by choosing hunks introduced by it that will be moved into the new split\-out commit\&. These hunks will then be written into a new commit that becomes the parent of the previous commit\&. The original commit stays intact, except that its parent will be the newly split\-out commit\&. .sp The commit messages of the split\-up commits will be asked for by launching the configured editor\&. Authorship of the commit will be the same as for the original commit\&. .sp If passed, \fI\fR can be used to limit which changes shall be split out of the original commit\&. Files not matching any of the pathspecs will remain part of the original commit\&. For more details, see the \fIpathspec\fR entry in \fBgitglossary\fR(7)\&. .sp It is invalid to select either all or no hunks, as that would lead to one of the commits becoming empty\&. .RE .SH "OPTIONS" .PP \fB\-\-dry\-run\fR .RS 4 Do not update any references, but instead print any ref updates in a format that can be consumed by \fBgit-update-ref\fR(1)\&. Necessary new objects will be written into the repository, so applying these printed ref updates is generally safe\&. .RE .PP \fB\-\-reedit\-message\fR .RS 4 Open an editor to modify the target commit\(cqs message\&. .RE .PP \fB\-\-empty=\fR(\fBdrop\fR|\fBkeep\fR|\fBabort\fR) .RS 4 Control what happens when a commit becomes empty as a result of the fixup\&. This can happen in two situations: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} The fixup target itself becomes empty because the staged changes exactly cancel out all changes introduced by that commit\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} A descendant commit becomes empty during replay because it introduced the same change that was just fixed up into an ancestor\&. .RE .sp With \fBdrop\fR (the default), empty commits are removed from the rewritten history\&. Descendants of a dropped target commit are replayed directly onto the target\(cqs parent\&. Note that dropping the root commit is not supported; see LIMITATIONS\&. .sp With \fBkeep\fR, empty commits are retained in the rewritten history as\-is\&. .sp With \fBabort\fR, the command stops with an error if any commit would become empty\&. .RE .PP \fB\-\-update\-refs=\fR(\fBbranches\fR|\fBhead\fR) .RS 4 Control which references will be updated by the command, if any\&. With \fBbranches\fR, all local branches that point to commits which are descendants of the original commit will be rewritten\&. With \fBhead\fR, only the current \fBHEAD\fR reference will be rewritten\&. Defaults to \fBbranches\fR\&. .RE .SH "EXAMPLES" .SS "Fixup a commit" .sp .if n \{\ .RS 4 .\} .nf $ git log \-\-oneline \-\-stat abc1234 (HEAD \-> main) third third\&.txt | 1 + def5678 second second\&.txt | 1 + ghi9012 first first\&.txt | 1 + $ echo "change" >>unrelated\&.txt $ git add unrelated\&.txt $ git history fixup ghi9012 $ git log \-\-oneline \-\-stat jkl3456 (HEAD \-> main) third third\&.txt | 1 + mno7890 second second\&.txt | 1 + pqr1234 first first\&.txt | 1 + unrelated\&.txt | 1 + .fi .if n \{\ .RE .\} .sp .sp The staged addition of \fBunrelated\&.txt\fR has been incorporated into the \fBfirst\fR commit\&. All descendant commits have been replayed on top of the rewritten history\&. .SS "Split a commit" .sp .if n \{\ .RS 4 .\} .nf $ git log \-\-stat \-\-oneline 3f81232 (HEAD \-> main) original bar | 1 + foo | 1 + 2 files changed, 2 insertions(+) $ git history split HEAD diff \-\-git a/bar b/bar new file mode 100644 index 0000000\&.\&.5716ca5 \-\-\- /dev/null +++ b/bar @@ \-0,0 +1 @@ +bar (1/1) Stage addition [y,n,q,a,d,p,?]? y diff \-\-git a/foo b/foo new file mode 100644 index 0000000\&.\&.257cc56 \-\-\- /dev/null +++ b/foo @@ \-0,0 +1 @@ +foo (1/1) Stage addition [y,n,q,a,d,p,?]? n $ git log \-\-stat \-\-oneline 7cebe64 (HEAD \-> main) original foo | 1 + 1 file changed, 1 insertion(+) d1582f3 split\-out commit bar | 1 + 1 file changed, 1 insertion(+) .fi .if n \{\ .RE .\} .sp .SH "GIT" .sp Part of the \fBgit\fR(1) suite