119

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.

1
  • 4
    You can use git add -u Commented May 16, 2014 at 16:12

3 Answers 3

141

The answer's here, I think.

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

Sign up to request clarification or add additional context in comments.

5 Comments

Ya I know that I should use git rm but rm is in my habit so sometimes I just forgot about using git rm.
Ah, sure, happens to me as well from time to time :)
Answer is git add -u, git commit -a, or git add -A? -1 for confusion.
git rm can be used after the rm has already deleted the file. It just updates the local repository.
git add <folder path with missing file>
103

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.

3 Comments

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.
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.
@MarkLongair now can you tell us about how can we undo this mistake :)
34

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>

2 Comments

This is confusing, though: 'use "git add/rm' — which is it? What's the difference, in this scenario, between the two?
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")

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.