rm
NAME名
git-rm - Remove files from the working tree and from the indexgit-rm - 作業ツリーとインデックスからファイルを削除する
SYNOPSIS概要
git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…
DESCRIPTION説明
Remove files 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.インデックス、または作業ツリーとインデックスからファイルを削除します。git rm
作業ディレクトリだけからファイルを削除することはありません。(作業ツリーからのみファイルを削除し、それをインデックスに保存するオプションはありません。削除する/bin/rm
場合はこれを使用してください。)削除するファイルはブランチの先端と同じである必要があります。そのデフォルトの振る舞いは-f
オプションで上書きすることができますが、それらの内容はインデックスでステージングすることができます。ときに--cached
指定され、段階的な内容は、ファイルがちょうどインデックスから削除することができるように、枝の先端またはディスク上のファイルのいずれかと一致する必要があります。
OPTIONSオプション
- <file>… <ファイル>…
-
Files to remove. Fileglobs (e.g.
*.c
) can be given to remove all matching files. If you want Git to expand file glob characters, you may need to shell-escape them. 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.削除するファイル ファイルグロブ(例*.c
)を指定すると、一致するすべてのファイルを削除できます。Gitにファイルグロブ文字を拡張させたい場合は、それらをシェルエスケープする必要があるかもしれません。ディレクトリ内のすべてのファイル、およびすべてのサブディレクトリを再帰的dir
に削除するためにdir/file1
、先頭にディレクトリ名(remove やなどdir/file2
)を付けることができますが、これには-r
明示的に指定するオプションが必要です。 - -f
- --force - 力
-
Override the up-to-date check.最新のチェックを無効にします。
- -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
-
Allow recursive removal when a leading directory name is given.先頭のディレクトリ名が与えられたときに再帰的な削除を許可します。
- -- -
-
This option can be used to separate command-line options from the list of files, (useful when filenames might be mistaken for command-line options).このオプションは、ファイルのリストからコマンドラインオプションを分離するために使用できます(ファイル名がコマンドラインオプションと間違えられる可能性がある場合に役立ちます)。
- --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
-
Exit with a zero status even if no files matched.ファイルが一致しない場合でも、ゼロのステータスで終了します。
- -q
- --quiet - 静か
-
git rm
normally outputs one line (in the form of anrm
command) for each file removed. This option suppresses that output.git rm
通常、rm
削除されたファイルごとに1行を(コマンドの形式で)出力します。このオプションはその出力を抑制します。
DISCUSSION討論
The <file> list given to the command can be exact pathnames, file glob patterns, or leading directory names. The command removes only the paths that are known to Git. Giving the name of a file that you have not told Git about does not remove that file.コマンドに与えられる<file>リストは、正確なパス名、ファイルグロブパターン、または先頭のディレクトリ名です。このコマンドは、Gitに認識されているパスのみを削除します。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
.ファイルグロビングはディレクトリの境界を越えて一致します。このように、2つのディレクトリを指定したd
とd2
、使用の間に差があるgit rm 'd*'
と、git rm 'd/*'
前者は、ディレクトリのすべてを削除しますように、d2
。
REMOVING FILES THAT HAVE DISAPPEARED FROM THE FILESYSTEMファイルシステムから消えたファイルを削除する
There is no option for git rm
to remove from the index only
the paths that have disappeared from the filesystem. However,
depending on the use case, there are several ways that can be
done.git rm
ファイルシステムから消えたパスだけをインデックスから削除することはできません。ただし、ユースケースに応じて、実行できる方法がいくつかあります。
Using “git commit -a”“ 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
.次回のコミットで追跡対象ファイルのすべての変更を作業ツリーに記録し、作業ツリーから削除されたファイルのすべての削除をrm
(とは対照的にgit rm
)git commit -a
記録する必要がある場合は、すべての削除を自動的に確認して記録します。 。を使用してコミットせずに同様の効果を得ることもできgit add -u
ます。
Using “git add -A”“ git add -A”を使う
When accepting a new code drop for a vendor branch, you probably want to record both the removal of paths and additions of new paths as well as modifications of existing paths.ベンダーブランチの新しいコードドロップを受け入れるときは、パスの削除と新しいパスの追加、および既存のパスの変更の両方を記録することをお勧めします。
Typically you would first remove all tracked files from the working tree using this command:通常、あなたは最初にこのコマンドを使ってワーキングツリーからすべての追跡されたファイルを削除するでしょう:
git ls-files -z | xargs -0 rm -f
and then untar the new code in the working tree. Alternately you could rsync the changes into the working tree.そしてワーキングツリーの新しいコードを展開します。あるいは、変更を作業ツリーに再同期することもできます。
After that, the easiest way to record all removals, additions, and modifications in the working tree is:その後、すべての削除、追加、および修正を作業ツリーに記録する最も簡単な方法は、次のとおりです。
git add -A
See git-add[1].git-add [1]を参照してください。
Other ways他の方法
If all you really want to do is to remove from the index the files
that are no longer present in the working tree (perhaps because
your working tree is dirty so that you cannot use git commit -a
),
use the following command:作業ツリーに存在しなくなったファイルをインデックスから削除するだけの場合は(おそらく作業ツリーが汚れているため使用できないためgit commit -a
)、次のコマンドを使用します。
git diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
SUBMODULESサブモジュール
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).リポジトリがスーパープロジェクトの.gitディレクトリ内にあるため、gitファイルを使用しているサブモジュール(つまり、Gitバージョン1.7.8以降で複製されたことを示すサブモジュール)のみが作業ツリーから削除されます。サブモジュール(またはその中にネストされているもの)がまだ.gitディレクトリを使用している場合git rm
は、サブモジュールの履歴を保護するために、サブモジュールのgitディレクトリをスーパープロジェクトのgitディレクトリに移動します。存在する場合は、gitmodules [5]ファイルのsubmodule。<name>セクションも削除され、そのファイルはステージングされます(--cachedまたは-nが使用されている場合を除く)。
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 submodules work tree. Ignored files are deemed expendable and won’t stop a submodule’s work tree from being removed.HEADがインデックスに記録されているものと同じで、追跡されたファイルが変更されず、無視されない追跡されていないファイルがサブモジュールの作業ツリーに存在しない場合、サブモジュールは最新と見なされます。無視されたファイルは消耗品と見なされ、サブモジュールの作業ツリーが削除されるのを防ぐことはできません。
If you only want to remove the local checkout of a submodule from your
work tree without committing the removal, use git-submodule[1] deinit
instead. Also see gitsubmodules[7] for details on submodule removal.作業モジュールからサブモジュールのローカルチェックアウトだけを削除せずに削除したい場合は、代わりにgit-submodule [1]を deinit
使用してください。サブモジュール削除の詳細についてはgitsubmodules [7]も参照してください。
EXAMPLES例
-
git rm Documentation/\*.txt
-
Removes all
*.txt
files from the index that are under theDocumentation
directory and any of its subdirectories.ディレクトリとそのサブディレクトリの*.txt
下にあるすべてのファイルをインデックスから削除しますDocumentation
。Note that the asterisk
*
is quoted from the shell in this example; this lets Git, and not the shell, expand the pathnames of files and subdirectories under theDocumentation/
directory.*
この例では、アスタリスクがシェルから引用されていることに注意してください。これにより、シェルではなくGitがディレクトリの下のファイルとサブディレクトリのパス名を拡張できますDocumentation/
。 -
git rm -f git-*.sh
-
Because this example lets the shell expand the asterisk (i.e. you are listing the files explicitly), it does not remove
subdir/git-foo.sh
.この例ではシェルがアスタリスクを展開することを許可しているので(つまり、ファイルを明示的にリストしている)、削除しませんsubdir/git-foo.sh
。
BUGSバグ
Each time a superproject update removes a populated submodule (e.g. when switching between commits before and after the removal) a stale submodule checkout will remain in the old location. Removing the old directory is only safe when it uses a gitfile, as otherwise the history of the submodule will be deleted too. This step will be obsolete when recursive submodule update has been implemented.スーパープロジェクトの更新によって、作成されたサブモジュールが削除されるたびに(削除の前後でコミットが切り替わるときなど)、古いサブモジュールのチェックアウトは古い場所に残ります。古いディレクトリを削除しても、gitfileを使用している場合にのみ安全です。それ以外の場合は、サブモジュールの履歴も削除されます。再帰的サブモジュール更新が実装されている場合、このステップは廃止されるでしょう。
SEE ALSO関連項目
GIT
Part of the git[1] suite一部のgit [1]スイート
関連記事
- write-tree
- verify-pack
- update-ref
- update-index
- symbolic-ref
- show-ref
- rev-parse
- rev-list
- read-tree
- merge-base
- ls-files
- hash-object
- for-each-ref
- diff-index
- count-objects
- commit-tree
- checkout-index
- check-ignore
- cat-file
- bundle
- archive
- instaweb
- filter-branch
- reflog
- fsck
- gc
- clean
- Workflows
- Tutorial
- Revisions
- gitmodules
- gitignore
- githooks
- Glossary
- Everyday Git
- gitattributes
- update-server-info
- daemon
- fast-import
- svn
- request-pull
- send-email
- format-patch
- am
- grep
- blame
- bisect
- revert
- rebase
- cherry-pick
- apply
- describe
- shortlog
- show
- submodule
- remote
- push
- pull
- fetch
- worktree
- tag
- stash
- log
- mergetool
- merge
- checkout
- branch
- mv
- reset
- commit
- diff
- status
- add
- clone
- init
- help
- config
- git
スポンサーリンク