Git
Português (Brasil) ▾Topics ▾Latest version ▾ git-rm last updated in 2.43.0

NOME

git-rm - Remove os arquivos da árvore de trabalho e do índice

RESUMO

git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch]
	  [--quiet] [--pathspec-from-file=<arquivo> [--pathspec-file-nul]]
	  [--] [<pathspec>…​]

DESCRIÇÃO

Remove files matching pathspec from the index, or from the working tree and the index. git rm will not remove a file from just your working directory. (There is no option to remove a file only from the working tree and yet keep it in the index; use /bin/rm if you want to do that.) The files being removed have to be identical to the tip of the branch, and no updates to their contents can be staged in the index, though that default behavior can be overridden with the -f option. When --cached is given, the staged content has to match either the tip of the branch or the file on disk, allowing the file to be removed from just the index. When sparse-checkouts are in use (see git-sparse-checkout[1]), git rm will only remove paths within the sparse-checkout patterns.

OPÇÕES

<pathspec>…​

Files to remove. A leading directory name (e.g. dir to remove dir/file1 and dir/file2) can be given to remove all files in the directory, and recursively all sub-directories, but this requires the -r option to be explicitly given.

O comando remove apenas os caminhos que sejam informados pelo Git.

File globbing matches across directory boundaries. Thus, given two directories d and d2, there is a difference between using git rm 'd*' and git rm 'd/*', as the former will also remove all of directory d2.

Para mais detalhes sobre a sintaxe, consulte a entrada pathspec em gitglossary[7].

-f
--force

Substitua a verificação atualizada.

-n
--dry-run

Don’t actually remove any file(s). Instead, just show if they exist in the index and would otherwise be removed by the command.

-r

Permita a remoção recursiva quando um nome do diretório principal for informado.

--

Esta opção pode ser utilizada para separar as opções da linha de comandos da lista dos arquivos (útil quando os nomes do arquivo puderem ser confundidos com as opções da linha de comando).

--cached

Use this option to unstage and remove paths only from the index. Working tree files, whether modified or not, will be left alone.

--ignore-unmatch

Encerre com uma condição zero, ainda que não haja a coincidência com nenhum arquivo.

--sparse

Allow updating index entries outside of the sparse-checkout cone. Normally, git rm refuses to update index entries whose paths do not fit within the sparse-checkout cone. See git-sparse-checkout[1] for more.

-q
--quiet

git rm normally outputs one line (in the form of an rm command) for each file removed. This option suppresses that output.

--pathspec-from-file=<arquivo>

O "pathspec" é passado com <arquivo> em vez dos argumentos da linha de comando. Caso o <arquivo> seja exatamente -, a entrada padrão será utilizada. Os elementos do "pathspec" são separados por caracteres de término de linha LF ou CR/LF. Os elementos do "pathspec" podem ser citados conforme explicado na variável de configuração core.quotePath (consulte git-config[1]). Consulte também opção --pathspec-file-nul e o global --literal-pathspecs.

--pathspec-file-nul

Só faz algum sentido caso seja utilizado junto com a opção --pathspec-from-file. Os elementos "pathspec" são separados com caracteres NUL e todos os outros caracteres são considerados de forma literal (incluindo as novas linhas e as citações).

REMOVENDO OS ARQUIVOS QUE DESAPARECERAM DO SISTEMA DE ARQUIVOS

Não há uma opção para o comando git rm para remover do índice apenas os caminhos que desapareceram do sistema de arquivos. No entanto, dependendo do caso, há várias maneiras de se fazer isso.

Utilizando o git commit -a

If you intend that your next commit should record all modifications of tracked files in the working tree and record all removals of files that have been removed from the working tree with rm (as opposed to git rm), use git commit -a, as it will automatically notice and record all removals. You can also have a similar effect without committing by using git add -u.

Utilizando git add -A

Ao aceitar um novo código para o fornecedor de um ramo, você provavelmente deseja registrar a remoção dos caminhos e as adições dos novos caminhos, bem como as modificações dos caminhos já existentes.

Normalmente, você primeiro remove todos os arquivos rastreados da árvore de trabalho utilizando este comando:

git ls-files -z | xargs -0 rm -f

e descompacte o novo código na árvore de trabalho. Como alternativa, você pode usar o comando rsync nas alterações na árvore de trabalho.

Depois disso, a maneira mais fácil de registrar todas as remoções, adições e modificações na árvore de trabalho é:

git add -A

Consulte git-add[1].

Outras maneiras

Se tudo o que você realmente deseja é remover do índice os arquivos que não estão mais presentes na árvore de trabalho (talvez porque a sua árvore de trabalho esteja suja e você não possa usar o comando git commit -a), utilize o seguinte comando:

git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached

SUBMÓDULOS

Only submodules using a gitfile (which means they were cloned with a Git version 1.7.8 or newer) will be removed from the work tree, as their repository lives inside the .git directory of the superproject. If a submodule (or one of those nested inside it) still uses a .git directory, git rm will move the submodules git directory into the superprojects git directory to protect the submodule’s history. If it exists the submodule.<name> section in the gitmodules[5] file will also be removed and that file will be staged (unless --cached or -n are used).

A submodule is considered up to date when the HEAD is the same as recorded in the index, no tracked files are modified and no untracked files that aren’t ignored are present in the submodule’s work tree. Ignored files are deemed expendable and won’t stop a submodule’s work tree from being removed.

Caso queira remover apenas a averiguação local de um submódulo vindo da sua árvore de trabalho sem fazer o commit de remoção, em vez disso utilize o git-submodule[1] deinit. Para obter mais detalhes sobre a remoção do submódulo, veja também gitsubmodules[7].

EXEMPLOS

git rm Documentation/\*.txt

Remove todos os arquivos * .txt do índice que estão no diretório Documentation e em qualquer um dos seus subdiretórios.

Note que o asterisco * é citado no shell neste exemplo; isso permite que o Git e não o shell, expanda os nomes dos caminhos dos arquivos e subdiretórios no diretório Documentation/.

git rm -f git-*.sh

Como este exemplo permite que o shell expanda o asterisco (ou seja, você está listando os arquivos explicitamente), ele não considera o subdir/git-foo.sh.

BUGS

Sempre que uma atualização do superproject remove um submódulo preenchido (por exemplo, ao alternar entre commits antes e após a remoção), um checkout obsoleto do submódulo permanece no local antigo. A remoção do diretório antigo só é segura quando ele usa um gitfile; caso contrário, o histórico do submódulo também será excluído. Esta etapa será obsoleta quando a atualização recursiva do submódulo for implementada.

VEJA TAMBÉM

GIT

Parte do conjunto git[1]

scroll-to-top