commit

async _AsyncGit.commit(message: Optional[Union[str, bool]], *args, repo: Optional[str] = None)str[source]

Calls git commit with the arguments -m "message" [args], where each positional argument passed after the message is passed as a command line argument.

To disable prepending -m to the arguments, pass None as the message and only your specified args will be passed along to git commit.

You may also set message to False which will call git commit --allow-empty-message [args] instead of prepending -m.

Basic Usage

Standard commit with a message, plus the argument ‘-a’:

>>> g = Git()
>>> g.commit("added example.txt", "-a")

Pass None as the message to disable prepending -m to the git arguments. For example, the following call commits the current staged changes, while re-using the commit message/author info/timestamp from the previous commit 9e27d7233ac5bc59bc37c0572a401068fbd5e6be:

>>> g.commit(None, "-C", "9e27d7233ac5bc59bc37c0572a401068fbd5e6be")

Pass False as the message for an easy way to call git commit --allow-empty-message, plus any additional arguments you might pass:

>>> g.commit(False, '-a')
Parameters
  • message (str|bool) – The git commit message to commit with. Alternatively None to remove the default -m, or False as a shortcut for --allow-empty-message instead of -m.

  • args – Additional CLI arguments to pass to git commit

  • repo (str) – (as a kwarg only!) An absolute path to a Git repository to run git commit within. By default, this is None which results in the repo passed in the constructor ( repo ) being used.

Return str stdout

The string text printed to stdout by git commit while running the command.