libgit2

git_commit_amend

Version:

Amend an existing commit by replacing only non-NULL values.

This creates a new commit that is exactly the same as the old commit, except that any non-NULL values will be updated. The new commit has the same parents as the old commit.

The update_ref value works as in the regular git_commit_create(), updating the ref to point to the newly rewritten commit. If you want to amend a commit that is not currently the tip of the branch and then rewrite the following commits to reach a ref, pass this as NULL and update the rest of the commit chain and ref separately.

Unlike git_commit_create(), the author, committer, message, message_encoding, and tree parameters can be NULL in which case this will use the values from the original commit_to_amend.

All parameters have the same meanings as in git_commit_create().

Signature

int git_commit_amend(git_oid *id, const git_commit *commit_to_amend, const char *update_ref, const git_signature *author, const git_signature *committer, const char *message_encoding, const char *message, const git_tree *tree);

Parameters

In
id

Pointer in which to store the OID of the newly created commit

In
commit_to_amend

The commit to amend

const char *
In
update_ref

If not NULL, name of the reference that will be updated to point to this commit. If the reference is not direct, it will be resolved to a direct reference. Use "HEAD" to update the HEAD of the current branch and make it point to this commit. If the reference doesn't exist yet, it will be created. If it does exist, the first parent must be the tip of this branch.

In
author

Signature with author and author time of commit

In
committer

Signature with committer and * commit time of commit

const char *
In
message_encoding

The encoding for the message in the commit, represented with a standard encoding name. E.g. "UTF-8". If NULL, no encoding header is written and UTF-8 is assumed.

const char *
In
message

Full message for this commit

In
tree

An instance of a git_tree object that will be used as the tree for the commit. This tree object must also be owned by the given repo.

Returns

int

0 or an error code The created commit will be written to the Object Database and the given reference will be updated to point to it

Versions