114

In my git repository I manually deleted a file(rm) after moving it to another folder. I than committed all the changes to my repo but now when I do git status .

ronnie@ronnie:/home/github/Vimfiles/Vim$ git status .
# 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:    plugin/dwm.vim
#
no changes added to commit (use "git add" and/or "git commit -a")

Now, how should I commit so that dwm.vim is deleted from the plugin folder in my remote repo. I know that I have to use git add && git commit but I have no file to commit/add because /plugin/dwm.vim is already deleted.

ronnie
  • 1,799
  • 3
  • 17
  • 22

3 Answers3

138

The answer's here, I think.

It's better if you do git rm <fileName>, though.

mfaani
  • 33,269
  • 19
  • 164
  • 293
s.m.
  • 7,895
  • 2
  • 38
  • 46
100

Use git add -A, this will include the deleted files.

Warning: this also adds all files in the directory that are not already in the repository.

Note: use git rm for certain files.

ferrouswheel
  • 3,658
  • 2
  • 24
  • 24
xdazz
  • 158,678
  • 38
  • 247
  • 274
  • 52
    If someone's just wanting to stage the deletion of a single file, I don't think it's a good idea to suggest `git add -A`, since that will also (a) stage all modifications to already tracked files and (b) stage untracked and unignored files. You might want to update your answer with a warning about that. – Mark Longair Oct 20 '12 at 11:36
  • on the other hand when you refactor an entire project and move/delete folders and files you can not get back to do that for just that reason each file/folder using git. git add -A should be event one command. – hephestos Jul 20 '18 at 07:27
  • 1
    @MarkLongair now can you tell us about how can we undo this mistake :) – NONONONONO Jul 07 '21 at 10:20
33

It says right there in the output of git status:

#   (use "git add/rm <file>..." to update what will be committed)

so just do:

git rm <filename>
Kache
  • 15,647
  • 12
  • 51
  • 79
  • 3
    This is confusing, though: 'use "git add/rm' — which is it? What's the difference, in this scenario, between the two? – Bobby Jack Jan 15 '19 at 12:08
  • Why not try them and find out? I think you'll find the behavior quite sensible in both cases. ("Add a deleted file" and "remove a deleted file") – Kache Jan 15 '19 at 13:57