Setup and Config
Getting and Creating Projects
Basic Snapshotting
Branching and Merging
Sharing and Updating Projects
Inspection and Comparison
Patching
Debugging
External Systems
Server Admin
- 2.43.1 → 2.45.2 no changes
- 2.43.0
11/20/23
- 2.34.1 → 2.42.3 no changes
- 2.34.0
11/15/21
- 2.32.1 → 2.33.8 no changes
- 2.32.0
06/06/21
- 2.26.1 → 2.31.8 no changes
- 2.26.0
03/22/20
- 2.16.6 → 2.25.5 no changes
- 2.15.4
12/06/19
- 2.14.6
12/06/19
- 2.13.7
05/22/18
- 2.1.4 → 2.12.5 no changes
- 2.0.5
12/17/14
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 removedir/file1
anddir/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
andd2
, there is a difference between usinggit rm 'd*'
andgit rm 'd/*'
, as the former will also remove all of directoryd2
.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 anrm
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 linhaLF
ouCR/LF
. Os elementos do "pathspec" podem ser citados conforme explicado na variável de configuraçãocore.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 caracteresNUL
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órioDocumentation
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órioDocumentation/
.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.
GIT
Parte do conjunto git[1]