I have a Git repo that I have deleted four files from using rm
(not git rm
), and my Git status looks like this:
# deleted: file1.txt
# deleted: file2.txt
# deleted: file3.txt
# deleted: file4.txt
How do I remove these files from Git without having to manually go through and add each file like this:
git rm file1 file2 file3 file4
Ideally, I'm looking for something that works in the same way that git add .
does, if that's possible.
None of the flags to git-add will only stage removed files; if all you have modified are deleted files, then you're fine, but otherwise, you need to run git-status and parse the output.
Working off of Jeremy's answer, this is what I got:
grep -v
lines.git rm
.Sticking this in a shell alias now...
As mentioned
stages the removed files for deletion, BUT ALSO modified files for update.
To unstage the modified files you can do
if you like to keep your commits organized and clean.
NOTE: This could also unstage the deleted files, so careful with those wildcards.
Removes all files listed by the
git ls-files
command (-d show only deleted files). Doesn't work for files with spaces in the filename or path, but simple to rememberThis worked for me after I had already deleted the files.
The following will work, even if you have a lot of files to process:
You'll probably also want to commit with a comment.
For details, see: Useful Git Scripts
(Yet another variation)
I wanted to delete all the already deleted from the disk files but from one specific folder, leaving the other folders untouched. The following worked for me: