105

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,709
  • 3
  • 17
  • 21

3 Answers3

129

The answer's here, I think.

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

mfaani
  • 28,843
  • 15
  • 145
  • 252
s.m.
  • 7,705
  • 2
  • 36
  • 44
95

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

Note: use git rm for certain files.

xdazz
  • 154,648
  • 35
  • 237
  • 264
  • 47
    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
  • @MarkLongair now can you tell us about how can we undo this mistake :) – NONONONONO Jul 07 '21 at 10:20
32

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
  • 13,141
  • 11
  • 49
  • 74
  • 1
    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