Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telling git its ok to remove untracked files [duplicate]

Possible Duplicate:
How do you remove untracked files from your git working copy?

Is it possible to tell git to remove untracked files? Mainly something that is similar to a reset?

example:

git checkout -- index.php <-- revert my file git checkout -- master <-- this would revert the entire repo back to the last commit on master, removing (deleting) any and all untracked files as well as reverting committed ones. 

I know this is trivial to do on the shell. But I'd like to know if this can be done in Git?

like image 749
zkolnik Avatar asked Sep 28 '11 19:09

zkolnik


People also ask

Can I delete untracked files?

You can use the git clean command to remove untracked files. The -fd command removes untracked directories and the git clean -fx command removes ignored and non-ignored files. You can remove untracked files using a . gitignore file.

Will git reset remove untracked files?

git reset --hard is a classic command in this situation - but it will only discard changes in tracked files (i.e. files that already are under version control). To get rid of new / untracked files, you'll have to use git clean !


2 Answers

You need git clean but add the -df to enable removing files that are in directories from where you are. Add x to include ignored files.

So to completely clean your working directory leaving only what is in source control, issue this command:

git clean -xdf 
like image 89
Adam Dymitruk Avatar answered Sep 24 '22 01:09

Adam Dymitruk


You may be looking for git clean. This will delete all untracked files. By default this ignores (does not delete) patterns in .gitignore, but git clean -x cleans those files too.

From the git clean man page:

   -x        Don't use the ignore rules. 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. 
like image 42
Greg Hewgill Avatar answered Sep 24 '22 01:09

Greg Hewgill