I have deleted some files and git status shows as below.
I have committed and pushed.
GitHub still shows the deleted files in the repository. How can I delete files in the GitHub repository?
# On branch master
# Changes not staged for commit:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: modules/welcome/language/english/kaimonokago_lang.php
# deleted: modules/welcome/language/french/kaimonokago_lang.php
# deleted: modules/welcome/language/german/kaimonokago_lang.php
# deleted: modules/welcome/language/norwegian/kaimonokago_lang.php
If I use git rm
, it gives the following.
usage: git rm [options] [--] <file>...
-n, --dry-run dry run
-q, --quiet do not list removed files
--cached only remove from the index
-f, --force override the up-to-date check
-r allow recursive removal
--ignore-unmatch exit with a zero status even if nothing matched
Update all changes you made:
The deleted files should change from unstaged (usually red color) to staged (green). Then commit to remove the deleted files:
Here is how to detect deleted files and stage their deletion as part of the next commit. All the solutions on this thread have different merits. This solution bellow specifically deals with the problem of file names with spaces in them.
make sure you test this with git's --dry-run option before running it with the following:
explanation:
This prints out something like D "/path to a folder/path to a file" which happens only when there are spaces in the path names
match only lines that start with " D "
remove " D " from the front of each string
remove quotes, if any
define file name variables as {} run file name under git rm enclosed in single quotes in order to make sure that it supports file names with spaces.
You can create a shell script which will remove all your files when run:
The script that is created is
remove.sh
and it contains the full list ofgit rm
commands.Be very cautious about
git rm .
; it might remove more than you want. Of course, you can recover, but it is simpler not to have to do so.Simplest would be:
You can't use shell wildcards because the files don't exist, but you could use (in Bash at least):
Or consider:
This takes the output of
git status
, doesn't print anything by default (sed -n
), but on lines that start# deleted:
, it gets rid of the#
and thedeleted:
and prints what is left;xargs
gathers up the arguments and provides them to agit rm
command. This works for any number of files regardless of similarity (or dissimilarity) in the names.