
git 删除未跟踪文件
As Git source code versioning software uses tracked and untracked terms to track files. We untracked files are generally added newly to the repository but there may be some bulk files those are unnecessary to version. In this tutorial, we will learn different ways to remove untracked files with Git.
作为Git源代码版本控制软件使用跟踪和未跟踪的术语来跟踪文件。 我们未跟踪的文件通常是新添加到存储库中的,但是可能会有一些批量文件是不需要版本的。 在本教程中,我们将学习使用Git删除未跟踪文件的不同方法。
列出要删除的文件 (List Files To Be Deleted)
Before deleting untracked files and folders we will list untracked files and folders. We will use clean
command with the -n
option like below.
在删除未跟踪的文件和文件夹之前,我们将列出未跟踪的文件和文件夹。 我们将使用带有-n
选项的clean
命令,如下所示。
$ git clean -n

强制删除或删除未跟踪的文件和文件夹(Delete or Remove Untracked Files and Folders Forcibly)
The most basic way to remove untracked files and folders is using clean
git command with the -f
option like below. -f
means remove and clean forcibly without asking anything.
删除未跟踪的文件和文件夹的最基本方法是使用带有-f
选项的clean
git命令,如下所示。 -f
表示不提出任何要求就强行删除和清洁。
$ git clean -f

仅删除未跟踪的目录(Remove Untracked Directories Only)
If we just need to remove or delete untracked directories we shouşd use -d
option with the remove command. -d
simply means removing only untracked directories.
如果只需要删除或删除未跟踪的目录,我们应该在删除命令中使用-d
选项。 -d
只是意味着仅删除未跟踪的目录。
$ git clean -f -d
仅删除未跟踪的文件 (Remove Untracked Files Only)
If we just want to remove untracked files only we need to use -X
option like below.
如果只想删除未跟踪的文件,则需要使用-X
选项,如下所示。
$ git clean -f -X
模拟试运行中删除未跟踪的文件和目录 (Simulate Remove Of Untracked Files and Directories with Dry Run)
Removing untracked files and directories may be a critical job where we can lose our latest work. So we can simulate or dry run removing untacked files with the --dry-run
option like below.
删除未跟踪的文件和目录可能是至关重要的工作,我们可能会丢失最新的工作。 因此,我们可以使用如下所示的--dry-run
选项模拟或试运行以删除未确认的文件。
$ git clean -d --dry-run

翻译自: https://www.poftut.com/how-to-remove-untracked-files-in-git/
git 删除未跟踪文件