git-rm command basic snapshot of the GIT

Name NAME

git-rm - remove files from the working tree and index

Overview SYNOPSIS

git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…​

Description DESCRIPTION

Delete files from the working tree and index or index.

git rm will not delete files only from your working directory. (No option to delete files and options can only work in their tree remain in the index; To do so, use the / bin / rm)

Deleted files must be the same as the tip of a branch, and no content updates can be temporarily stored in the index, although you can use the -f option to override the default behavior. If --cached specified, must match the contents of the temporary files on the disk or the tip of a branch, allowing delete files only from the index.

Options OPTIONS

<file>…​

To delete files

You can use wildcards (eg * .c) delete all files that match. You can specify a leading directory name (for example, delete dir dir / file1 and dir / file2) to delete all the files in a directory and all subdirectories recursively delete, but this requires explicit give the -r option.

-f    --force

Override the up-to-date check.

-n    --dry-run

It does not actually delete any files. But to show whether they are present in the index, otherwise the command will be deleted. .

-r

Given leading directory name, it allows recursive delete.

--

This option can be used to command line options and a list of files separately (when the file name may be mistaken for useful command line option).

--cached

Use this option to cancel the temporary index is deleted and only path. Working tree file, whether or not modified, they will be retained.

--ignore-unmatch

Even if there is no matching file, it exits with a zero status.

-q

--quiet

git rm 通常为删除的每个文件输出一行(以rm命令的形式)。 此选项禁止输出。

Discussion DISCUSSION

To the command <file> list may be the exact path name or wildcard patterns leading directory names. This command deletes only Git known path. Provided you do not advise Git file name does not delete the file.

File directory traversal cross-border match. Thus, given two directories d and d2, use git rm 'd *' and git rm 'd / *' is different, because the former will delete all directory d2.

Deleted from the file system, the file disappears

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.

There is no option option allows git rm to delete the file system path has disappeared from the index. However, depending on usage, there are several ways to do.

Use "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.

Use "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

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 diff --name-only --diff-filter=D -z | xargs -0 git rm --cached
Published 217 original articles · won praise 136 · Views 1.37 million +

Guess you like

Origin blog.csdn.net/ystyaoshengting/article/details/104069710
Recommended