In Mercurial I can do this with the bundled Purge Extension and executing the following command:
hg purge
Also good to get rid of ignored files:
hg purge --all
I’m curious about the most practical/used equivalent solution in git.
Edit: I want to just get rid of the untracked files, not reset everything (e.g. suppose I have a program generating cache files or generated code and I want to delete them with git’s help)
1
It’s git reset with the option –hard:
git reset --hard
Here is an SO answer which have more details:
https://stackoverflow.com/a/9530204/70386
And the manual:
http://www.kernel.org/pub/software/scm/git/docs/git-reset.html
Edit
To only delete untracked files, use clean
https://stackoverflow.com/questions/61212/removing-untracked-files-from-your-git-working-copy
Manual entry:
http://www.kernel.org/pub/software/scm/git/docs/git-clean.html
2
For all git clean
commands, add -n
for dry-run.
Clean all untracked files and directories, except ignored files (listed in .gitignore):
git clean -fd
Also clean ignored files:
git clean -fdx
Only clean ignored files (useful for removing build artifacts, to ensure a fresh build from scratch, without discarding new files/directories you haven’t committed yet):
git clean -fdX