git-rewrite-commit - rewrite the HEAD commit reusing the current HEAD
git rewrite-commit [--root]
git rewrite-commit <parent>...
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:
The environment variable GIT_REWRITE_DEBUG can be set to a non-empty value to get a trace of git rewrite-commit operations.
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.
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.
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
git commit-tree(1)