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, passNone
as themessage
and only your specifiedargs
will be passed along togit commit
.You may also set
message
toFalse
which will callgit 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 commit9e27d7233ac5bc59bc37c0572a401068fbd5e6be
:>>> g.commit(None, "-C", "9e27d7233ac5bc59bc37c0572a401068fbd5e6be")
Pass
False
as the message for an easy way to callgit 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
, orFalse
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 isNone
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.