git rewrite-commit (1)

NAME

git-rewrite-commit - rewrite the HEAD commit reusing the current HEAD

SYNOPSIS

git rewrite-commit [--root]
git rewrite-commit <parent>...

DESCRIPTION

This command rewrites the HEAD commit keeping its current values except those that are explicitly overridden. In particular, running git rewrite-commit without setting any properties should leave the current HEAD commit as is.

The set of parent commits of the new HEAD commit are given as arguments on the commandline. If no argument is given, the parents of the HEAD commit are reused. If the new commit should have no parent, the --root option should be used.

All the other parameters of the new commit are passed as environment variables. Those parameters are:

GIT_COMMIT_TREE
its tree object
GIT_COMMIT_MESSAGE
its complete message
GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_AUTHOR_DATE
see git commit-tree
GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, GIT_COMMITTER_DATE
see git commit-tree

OPTION

The environment variable GIT_REWRITE_DEBUG can be set to a non-empty value to get a trace of git rewrite-commit operations.

EXIT STATUS

git rewrite-commit exits with a value 1 when it is called with a dirty working directory, since this could lose changes, or when the arguments were improperly set.

BUGS

git rewrite-commit does not handle all features, such as signed commits or notes, etc. at the moment. The list of parameters states the supported features.

Even without any overridden parameter and any unsupported feature, git rewrite-commit can produce a different commit when the message is not formatted as is usual in git, namely when the message does not begin with a one-line summary followed by a blank line. In those cases, git glues all the lines into a long one.

EXAMPLE

git rewrite-commit can be used, along with git rm -r, to create a new root in a repository:

git checkout -b newroot
git rm -r .

... write, edit, amend

git commit
git rewrite-commit --root

SEE ALSO

git commit-tree(1)