<Git>git clean

本文深入解析Git Clean命令的使用方法及选项,如删除未跟踪文件、目录,强制删除及交互模式等,帮助开发者掌握如何清理工作目录,实现构建环境的纯净状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

git-clean - Remove untracked files from the working tree

从工作目录中删除没有tracked过的文件

git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>…​

Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.

Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. This can, for example, be useful to remove all build products.

If any optional <path>... arguments are given, only those paths are affected.

 

-d

Remove untracked directories in addition to untracked files.

删除当前目录下没有被track过的文件夹

-x

Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in conjunction with git reset) to create a pristine working directory to test a clean build.

删除当前目录下没有被track过的文件

-f

--force

If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to delete files or directories unless given -f, -n or -i. Git will refuse to delete directories with .git sub directory or file unless a second -f is given.

强制删除

网上貌似好多人都翻译成文件,扯淡。

看一下man手册:

GIT-CLEAN(1)                                                     Git Manual                                                    GIT-CLEAN(1)

NAME
       git-clean - Remove untracked files from the working tree

SYNOPSIS
       git clean [-d] [-f] [-i] [-n] [-q] [-e <pattern>] [-x | -X] [--] <path>...

DESCRIPTION
       Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.

       Normally, only files unknown to Git are removed, but if the -x option is specified, ignored files are also removed. This can, for
       example, be useful to remove all build products.

       If any optional <path>... arguments are given, only those paths are affected.

OPTIONS
       -d
           Remove untracked directories in addition to untracked files. If an untracked directory is managed by a different Git repository,
           it is not removed by default. Use -f option twice if you really want to remove such a directory.

       -f, --force
           If the Git configuration variable clean.requireForce is not set to false, git clean will refuse to run unless given -f, -n or
           -i.

       -i, --interactive
           Show what would be done and clean files interactively. See “Interactive mode” for details.

       -n, --dry-run
           Don’t actually remove anything, just show what would be done.

       -q, --quiet
           Be quiet, only report errors, but not the files that are successfully removed.

       -e <pattern>, --exclude=<pattern>
           In addition to those found in .gitignore (per directory) and $GIT_DIR/info/exclude, also consider these patterns to be in the
           set of the ignore rules in effect.
       -x
           Don’t use the standard ignore rules read from .gitignore (per directory) and $GIT_DIR/info/exclude, but do still use the ignore
           rules given with -e options. This allows removing all untracked files, including build products. This can be used (possibly in
           conjunction with git reset) to create a pristine working directory to test a clean build.

       -X
           Remove only files ignored by Git. This may be useful to rebuild everything from scratch, but keep manually created files.

 

<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>io.iec.edp</groupId> <artifactId>caf-boot-parent</artifactId> <version>2.0.0-rc.3</version> </parent> <groupId>com.inspur.edp</groupId> <artifactId>ide-setting</artifactId> <packaging>pom</packaging> <version>0.2.0-SNAPSHOT</version> <scm> <connection>scm:git:https://git.iec.io/gsp-cloud-ds/metadata/ide-setting.git</connection> <developerConnection>scm:git:ssh://git@git.iec.io:6060/gsp-cloud-ds/metadata/ide-setting.git</developerConnection> <url>https://git.iec.io/gsp-cloud-ds/metadata/ide-setting.git</url> <tag>HEAD</tag> </scm> <modules> <module>ide-setting-api</module> <module>ide-setting-core</module> <module>ide-setting-webapi</module> </modules> <build> <plugins> <plugin> <groupId>org.openclover</groupId> <artifactId>clover-maven-plugin</artifactId> <configuration> <includesTestSourceRoots>false</includesTestSourceRoots> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <version>3.6.3</version> <configuration> <skip>true</skip> <failOnError>false</failOnError> <excludePackageNames>com.inspur.edp.*</excludePackageNames> <sourcepath>${project.build.directory}/generated-sources/delombok</sourcepath> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-release-plugin</artifactId> <version>2.5.3</version> <configuration> <tagNameFormat>v@{project.version}</tagNameFormat> <pushChanges>false</pushChanges> </configuration> </plugin> </plugins> </build> <dependencyManagement> <dependencies> <dependency> <groupId>com.inspur.edp</groupId> <artifactId>ide-setting-api</artifactId> <version>${project.version}</version> </dependency> <dependency> <groupId>com.inspur.edp</groupId> <artifactId>metadata-service-dev-common</artifactId> <version>${metadata-service-dev.version}</version> </dependency> <dependency> <groupId>com.inspur.edp</groupId> <artifactId>metadata-service-dev-api</artifactId> <version>${metadata-service-dev.version}</version> </dependency> <dependency> <groupId>com.inspur.edp</groupId> <artifactId>metadata-service-inner-api</artifactId> <version>${metadata-service.version}</version> </dependency> <dependency> <groupId>com.inspur.edp</groupId> <artifactId>workspace-api</artifactId> <version>${workspace.version}</version> </dependency> <dependency> <groupId>com.inspur.edp</groupId> <artifactId>workspace-core</artifactId> <version>${workspace.version}</version> </dependency> <dependency> <groupId>com.inspur.edp</groupId> <artifactId>lcm-maven-utils</artifactId> <version>${lcm-maven-utils.version}</version> </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-settings</artifactId> <version>${apache.maven.settings.version}</version> </dependency> <dependency> <groupId>io.iec.edp</groupId> <artifactId>caf-security-core</artifactId> <version>${caf-security-core.version}</version> </dependency> <dependency> <groupId>io.iec.edp</groupId> <artifactId>caf-framework-authentication-api</artifactId> <version>${caf.authentication.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>io.iec.edp</groupId> <artifactId>caf-framework-authentication-core</artifactId> <version>${caf.authentication.version}</version> <exclusions> <exclusion> <groupId>*</groupId> <artifactId>*</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </dependencyManagement> <properties> <metadata-service.version>0.2.0-rc.2</metadata-service.version> <metadata-service-dev.version>0.2.0-rc.3</metadata-service-dev.version> <workspace.version>0.2.0-rc.4</workspace.version> <lcm-maven-utils.version>0.2.0-rc.3</lcm-maven-utils.version> <caf-security-core.version>2.0.0-rc.1</caf-security-core.version> <apache.maven.settings.version>3.8.6</apache.maven.settings.version> <caf.authentication.version>2.0.0-rc.3</caf.authentication.version> </properties> <distributionManagement> <repository> <id>gsp-releases-repo</id> <url>https://repos.iec.io/repository/maven-gsp-releases/</url> </repository> <snapshotRepository> <id>gsp-snapshots-repo</id> <url>https://repos.iec.io/repository/maven-gsp-snapshots/</url> </snapshotRepository> </distributionManagement> </project>
最新发布
08-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值