Unable to make Git ask about removal of deleted files

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?

Upvotes: 2

Views: 164

Answers (2)

August Lilleaas
August Lilleaas

Reputation: 54603

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.

Upvotes: 1

VonC
VonC

Reputation: 1326376

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

Upvotes: 4

Related Questions