![]() ![]() If we dry run the Git Clean command with just the -f flag, then it returns the following output. In such cases, it removes all untracked files matching the file path.įor example, consider a repository with one untracked file( demo.txt) and an untracked directory( New Folder). Note that the -d option is irrelevant if a path is passed to the Git Clean command. If an untracked directory is a Git Repository or a Submodule, we must use the -f option twice. Git clean -fd # equivalent to the above command The -d option allows us to delete untracked directories as well. It will not remove any untracked directories. Removing demo2.txt Git Clean with -d optionĪ simple Git Clean command will only delete untracked files. git clean -fįor example, if our repository contains two untracked files( demo1.txt and demo2.txt), then the git clean -fcommand will delete these two files and return the following output. It is a good practice to always include this option with the Git Clean command when you want to remove untracked files. So Git adds this safety feature and uses the -f flag for confirmation.Īccording to Git Documentation, the -f option will delete untracked files even when the Git configuration variable clean.requireForce is not set to false. An untracked file, once deleted, cannot be recovered. This option allows us to execute the Git Clean command and delete files. git clean -dry-run Output:Īs we can see in the output, Git tells that demo1.txt and demo2.txt would be removed if we run Git Clean without the -n option. If we dry run the Git Clean command, we will get the following output. git clean -nįor example, consider a Git repository with two untracked files( demo1.txt and demo2.txt). ![]() Note that it will not affect or delete any untracked files. It outputs the file names that will be removed. Git Clean command with the -n or -dry-run option will perform a dry run. A dry run allows us to view the untracked files that will be removed when the actual command is executed. Git Remove Untracked Files using Command from Working AreaĪs mentioned above, once deleted, an untracked file cannot be restored. ![]()
0 Comments
Leave a Reply. |