Created
January 20, 2012 19:02
-
-
Save matthewmccullough/1649017 to your computer and use it in GitHub Desktop.
Bash script to remove any ignored files that are accidentally tracked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Git Remove (from version control) any file that is covered by the ignore patterns and exists on the filesystem. Could be improved to further check the file exists on the git filesystem too. | |
for eachthing in `git ls-files --others --ignored --exclude-standard`; do if [ -e "$eachthing" ]; then git rm $eachthing; fi; done |
@cbeams This ls-files lists the ignored files in a decoration-less way that can be piped to a git rm command. Clean would wipe them out, but then you'd have to stage the removals. And then, what if you didn't want to stage some other changed (but not removed) files? git add -u .
would gum you up there by grabbing files you didn't want to stage. Let me know if that helps explain. Would like to sharpen the message for other consumers of the script as much as I can.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Interesting - what does this do that
git clean -dfx
orgit clean -dfX
(or some othergit clean
combo) couldn't?