![]() An example use case for this could be when you want to clean out a folder that contains build artifacts. In some situations, you might also - in addition to untracked files - want to delete any ignored files. If you want to include them, you can use the "-d" flag: $ git clean -fd If you want to only delete untracked files in a certain subdirectory of your project, you can additionally specify a path: $ git clean -f folder/subfolderīy default, folders themselves will no be deleted. To actually allow git clean to delete files in your working copy, you'll have to use the "force" option: $ git clean -f If this looks correct, you can proceed without the safety catch. "Dry run" means that Git will not actually perform any deletions, but it only tells you which files would be deleted. This is why the first step when approaching git clean is to make use of its "dry run" functionality using the "-n" flag: $ git clean -n Whatever options and parameters you provide: using git clean will only affect untracked files - in our example img/iconFacebook.png and login.html - and leave anything else untouched.īefore you use git clean to delete untracked files, you should remember an important detail: untracked files, by definition, aren't included in version control - and this means that when you delete them, you will not be able to restore them! In this tutorial, we'll see how to discard changes in our working directory that are not in the index. " to discard changes in working directory) A Git working directory can contain different types of files including staged files, unstaged files, and untracked files. Let's take a look at an example scenario: $ git status To get rid of new / untracked files, you'll have to use git clean! Usage Examples and Options files that already are under version control). git reset -hard is a classic command in this situation - but it will only discard changes in tracked files (i.e. Let's say you've programmed yourself into a dead end and want to start over, with a clean working copy. (Take a look at our First Aid Kit video series for other commands and workflows to undo mistakes.)Ĭompared to reset or revert, which are also classic undo commands, git clean is different: it targets untracked files that haven't been added to version control, yet. With the -staged option, however, the file will only be removed from the Staging Area - but its actual modifications will remain untouched. The clean command is one of Git's many "undo" tools. By default, the git restore command will discard any local, uncommitted changes in the corresponding files and thereby restore their last committed state. How to remove untracked files with git clean
0 Comments
Leave a Reply. |