git 删除未跟踪文件_如何在Git中删除未跟踪的文件?

git 删除未跟踪文件

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
List Files To Be Deleted
List Files To Be Deleted
列出要删除的文件

强制删除或删除未跟踪的文件和文件夹(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
Delete or Remove Untracked Files and Folders Forcibly
Delete or Remove Untracked Files and Folders Forcibly
强制删除或删除未跟踪的文件和文件夹

仅删除未跟踪的目录(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
Simulate Remove Of Untracked Files and Directories with Dry Run
Simulate Remove Of Untracked Files and Directories with Dry Run
模拟试运行中删除未跟踪的文件和目录
LEARN MORE  How to Install Git on Linux, Mac, or Windows?
了解更多如何在Linux,Mac或Windows上安装Git?

翻译自: https://www.poftut.com/how-to-remove-untracked-files-in-git/

git 删除未跟踪文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值