Class: Git::Commands::Reset Private

Inherits:
Base
  • Object
show all
Defined in:
lib/git/commands/reset.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-reset/2.53.0

Implements the git reset command

Resets the current HEAD to a specified state, or updates the staged version of specified files to match the state from a given commit or tree.

Examples:

Reset to HEAD (unstage all changes)

reset = Git::Commands::Reset.new(execution_context)
reset.call

Hard reset to a specific commit

reset = Git::Commands::Reset.new(execution_context)
reset.call('HEAD~1', hard: true)

Soft reset (preserve staged changes)

reset = Git::Commands::Reset.new(execution_context)
reset.call('HEAD~1', soft: true)

Reset specific files to HEAD (unstage)

reset = Git::Commands::Reset.new(execution_context)
reset.call(pathspec: ['file.rb'])

Reset specific files to a commit's version

reset = Git::Commands::Reset.new(execution_context)
reset.call('HEAD~1', pathspec: ['file.rb'])

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(commit = nil, **options) ⇒ Git::CommandLineResult

Execute the git reset command.

Returns the result of calling git reset.

Parameters:

  • commit (String, nil) (defaults to: nil)

    (nil) commit or tree-ish to reset to; defaults to HEAD when not given

  • options (Hash)

    command options

Options Hash (**options):

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

    leave working tree and index unchanged; reset HEAD to the specified commit

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

    reset the index but not the working tree; default mode when no mode flag is given

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

    mark removed paths as intent-to-add; only meaningful alongside :mixed

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

    reset the index and working tree to the specified commit; discards all tracked changes since that commit

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

    reset the index and update files that differ between the commit and HEAD, while preserving uncommitted changes

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

    reset index entries and update files that differ between the commit and HEAD; aborts if any such file has local changes

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

    suppress all output; report errors only (--quiet)

    Alias: :q

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

    do not suppress output (--no-quiet)

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

    refresh the index after a mixed reset; enabled by default when omitted (--refresh)

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

    do not refresh the index after a mixed reset (--no-refresh)

  • :unified (Integer, String) — default: nil

    number of context lines around each diff hunk

    Alias: :U

  • :inter_hunk_context (Integer, String) — default: nil

    number of context lines to show between diff hunks

  • :pathspec_from_file (String) — default: nil

    read pathspec from the given file; pass "-" to read from standard input

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

    delimit pathspec elements with NUL when reading from :pathspec_from_file; only meaningful alongside :pathspec_from_file

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

    also reset the working tree of all active submodules to the commit recorded in the superproject (--recurse-submodules)

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

    do not reset submodule working trees (--no-recurse-submodules)

  • :pathspec (Array<String>) — default: nil

    path(s) to reset in the index; when given, only the index entries for the matching paths are updated

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/reset.rb', line 75