Class: Git::Commands::Rm Private

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

Implements the git rm command

This command removes files from the working tree and from the index.

Examples:

Remove a tracked file

rm = Git::Commands::Rm.new(execution_context)
rm.call('file.txt')

Remove multiple files

rm = Git::Commands::Rm.new(execution_context)
rm.call('file1.txt', 'file2.txt')

Remove a directory recursively

rm = Git::Commands::Rm.new(execution_context)
rm.call('directory', r: true)

Remove from the index only (keep working tree copy)

rm = Git::Commands::Rm.new(execution_context)
rm.call('file.txt', cached: true)

Force removal of modified files

rm = Git::Commands::Rm.new(execution_context)
rm.call('modified_file.txt', force: true)

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 rm command

Parameters:

  • pathspec (Array<String>)

    files or directories to be removed from the repository (relative to the worktree root)

    At least one positional pathspec or the :pathspec_from_file option must be provided; git will fail at runtime if neither is given.

  • options (Hash)

    command options

Options Hash (**options):

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

    override the up-to-date check and remove files with local modifications

    Alias: :f

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

    do not actually remove any files; instead, just show if they exist in the index and would otherwise be removed by the command

    Alias: :n

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

    allow recursive removal when a leading directory name is given

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

    only remove from the index, keeping the working tree files

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

    exit with a zero status even if no files matched

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

    allow updating index entries outside of the sparse-checkout cone

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

    suppress the one-line-per-file output

    Alias: :q

  • :pathspec_from_file (String) — default: nil

    read pathspec from the given file, one pathspec element per line; pass - to read from standard input

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

    when used with :pathspec_from_file, separate pathspec elements with NUL instead of newlines

Returns:

Raises:

  • (ArgumentError)

    if unsupported options are provided

  • (Git::FailedError)

    if git exits with a non-zero exit status



# File 'lib/git/commands/rm.rb', line 55