i am used to rcs. after checking in, i usually do an rcsclean to remove all of the tracked fines that are present, so that only untracked files are present in the directory. i sometimes do an rcsclean -u to undo any changed to tracked files.
how do i do this in git?
afterwards there should be only untracked files in the current directory and it's subdirectories (except of course for the .git repository itself).
TL;DR
Git isn't RCS. You can do what you want, but you will cause yourself long-term suffering by trying to treat a Git repository as a file-based revision control system.
You can remove the files Git is tracking, but projects with larger/deeper directory trees will require you to take extra steps to remove empty directories (which Git doesn't track as first-class objects), and you will lose the ability to do things like
git commit -awithout Git thinking you're deleting all your files.Removing Files and Directories
You can remove all the files Git knows about by using the
ls-filessubcommand. You need to pipe the output to xargs because thermcommand doesn't handle null-terminated strings natively, and paths like "foo bar/baz quux" would cause problems without them.To remove all files committed to Git:
However, Git doesn't really track directories; it tracks trees. So, unless you have all your files in the root of the project, you'll need to remove the empty directories yourself as a separate command if you want them gone too. For example:
Commands to Avoid After Cleaning
Once you've done this, you'll need to avoid commands like
git commit -awhich will treat all the missing files as deleted. Instead, you'll have to stage files much more carefully. You might also want to investigateman git-update-indexand consider whether the--assume-unchangedflag will help your situation or make it worse.In addition, the
git statuscommand will continue to show lots of changes because you've deleted files from the working tree. If you have large numbers of files that you've "cleaned" from your working tree, the output of commands likegit statusmay become so cluttered that it becomes useless without filtering. For example, to find files that are really untracked rather than deleted or modified: