views:

102

answers:

2

Assume you have a file which has been committed in your Git repo.

You remove the file simply by

rm file

The removed file remains in your Git repo although you do not have it.

My old Git complained me that you cannot commit before you git add/rm the file at a similar situation. I would like to have the same behavior back.

How can you make Git not to allow you to commit without solving the problem with the file's existence first?

+3  A: 

What about using:

$ git commit -a

From git commit manual page:

The command git commit -a first looks at your working tree, notices that you have modified hello.c and removed goodbye.c, and performs necessary git add and git rm for you.


If you do not want an automatic resolution, but only a warning, a 'pre-commit hook' is in order.

 chmod a+x .git/hooks/pre-commit

That script would test the output of

 git ls-files -d

And warn you about deleted (but not 'git rm'ed) files

VonC
Better yet, parse in the pre-commit hook the result of 'git diff-files --name-status': if a line begins by D, exit with a warning message
VonC
@VonC: Thank you for your answer! --- I had an idea that `git commit -am "hello"` is the same as `git add .; git commit -m `hello`. --- So `git commit -a` just removes files which I have removed "physically".
Masi
+1  A: 

Even though the file does not exist in your file system, it exists in the git repository. Someone cloning the repo will get the file, even though it isn't there on your box.

August Lilleaas