Class: Git::Commands::Commit Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/commit.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Note:

arguments block audited against https://git-scm.com/docs/git-commit/2.53.0

Implements the git commit command

This command records changes to the repository by creating a new commit with the staged changes.

Examples:

Typical usage

commit = Git::Commands::Commit.new(execution_context)
commit.call(message: 'Initial commit')
commit.call(message: 'Add feature', all: true, author: 'Jane <jane@example.com>')
commit.call(amend: true, no_verify: true)  # emits --no-verify
commit.call('src/foo.rb', message: 'Update foo')

See Also:

Instance Method Summary collapse

Methods inherited from Base

allow_exit_status, arguments, #initialize, requires_git_version, skip_version_validation

Constructor Details

This class inherits a constructor from Git::Commands::Base

Instance Method Details

#call(*pathspec, **options) ⇒ Git::CommandLineResult

Execute the git commit command.

Parameters:

  • pathspec (Array<String>)

    zero or more paths to commit

    When given, only changes to the listed paths are committed, ignoring staged changes for other paths.

  • options (Hash)

    command options

Options Hash (**options):

  • :all (Boolean, nil) — default: nil

    automatically stage modified and deleted files before committing

    Alias: :a

  • :edit (Boolean, nil) — default: nil

    open an editor for the commit message (--edit)

    Alias: :e

  • :no_edit (Boolean, nil) — default: nil

    suppress the editor (--no-edit)

  • :amend (Boolean, nil) — default: nil

    replace the tip of the current branch with a new commit

  • :reuse_message (String) — default: nil

    reuse the log message and authorship from the given commit without invoking an editor

    Alias: :C

  • :fixup (String) — default: nil

    create a fixup or amend commit targeting the given commit

    Pass <commit> for a plain "fixup!" commit, amend:<commit> to also replace the log message, or reword:<commit> to replace only the log message.

  • :squash (String) — default: nil

    construct a "squash!" commit message for use with git rebase --autosquash

  • :message (String) — default: nil

    use the given string as the commit message

    Alias: :m

  • :file (String) — default: nil

    read the commit message from the given file; use - to read from standard input

    Alias: :F

  • :template (String) — default: nil

    start the editor with the contents of the given file as the commit message template

    Alias: :t

  • :reset_author (Boolean, nil) — default: nil

    when used with :reuse_message or :amend, declare the committer as the new author

  • :author (String) — default: nil

    override the commit author

  • :date (String) — default: nil

    override the author date

  • :cleanup (String) — default: nil

    how to clean up the commit message before committing; one of strip, whitespace, verbatim, scissors, or default

  • :trailer (String, Array<String>) — default: nil

    add one or more <token>[=<value>] trailers to the commit message

  • :verify (Boolean, nil) — default: nil

    run pre-commit and commit-msg hooks (--verify)

    Alias: :n

  • :no_verify (Boolean, nil) — default: nil

    bypass pre-commit and commit-msg hooks (--no-verify)

  • :allow_empty (Boolean, nil) — default: nil

    allow committing with no changes

  • :allow_empty_message (Boolean, nil) — default: nil

    allow committing with an empty message

  • :no_post_rewrite (Boolean, nil) — default: nil

    bypass the post-rewrite hook

  • :include (Boolean, nil) — default: nil

    stage the listed paths before committing in addition to already-staged contents

    Alias: :i

  • :only (Boolean, nil) — default: nil

    commit only the listed paths from the working tree, ignoring staged changes for other paths

    Alias: :o

  • :dry_run (Boolean, nil) — default: nil

    do not create a commit; show what would be committed

  • :short (Boolean, nil) — default: nil

    show short-format dry-run output; implies :dry_run

  • :branch (Boolean, nil) — default: nil

    show branch and tracking info in short-format dry-run output

  • :porcelain (Boolean, nil) — default: nil

    show porcelain-format dry-run output; implies :dry_run

  • :long (Boolean, nil) — default: nil

    show long-format dry-run output; implies :dry_run

  • :null (Boolean, nil) — default: nil

    terminate dry-run output entries with NUL instead of LF

    Alias: :z

  • :verbose (Boolean, Integer, nil) — default: nil

    show unified diff between HEAD and what would be committed at the bottom of the commit message template

    Pass 2 to also show the unified diff between staged and working-tree changes.

    Alias: :v

  • :quiet (Boolean, nil) — default: nil

    suppress commit summary message

    Alias: :q

  • :status (Boolean, nil) — default: nil

    include git status output in the commit message template (--status)

  • :no_status (Boolean, nil) — default: nil

    omit git status output from the commit message template (--no-status)

  • :unified (Integer) — default: nil

    generate verbose diff with the given number of context lines

    Alias: :U

  • :inter_hunk_context (Integer) — default: nil

    show context between diff hunks up to the given number of lines (for use with :verbose)

  • :signoff (Boolean, nil) — default: nil

    add a Signed-off-by trailer to the commit message (--signoff)

    Alias: :s

  • :no_signoff (Boolean, nil) — default: nil

    suppress the Signed-off-by trailer (--no-signoff)

  • :gpg_sign (Boolean, String, nil) — default: nil

    GPG-sign the commit (--gpg-sign)

    When true, uses the default key. When a String, uses the specified key ID.

    Alias: :S

  • :no_gpg_sign (Boolean, nil) — default: nil

    disable GPG signing, overriding commit.gpgSign config (--no-gpg-sign)

  • :untracked_files (Boolean, String, nil) — default: nil

    show untracked files in the dry-run status output

    When true, uses git's default mode (all). Pass a String ("no", "normal", or "all") to set the mode explicitly.

    Alias: :u

  • :pathspec_from_file (String) — default: nil

    read pathspec from the given file instead of the command line

  • :pathspec_file_nul (Boolean, nil) — default: nil

    pathspec elements in :pathspec_from_file are NUL-separated instead of newline-separated

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/commit.rb', line 96