Getting "git rm" to work

I thought I could remove files from Git pretty easily with essentially :

  $ git rm myfile.php
  $ git commit -m "Removing a file"

But I was getting this error upon commit : "Could not open input file myfile.php"

This is how I got it to work. The Git Cheat Sheet ( described this as "Commit the absence of myfile.txt to the project"

  $ git rm --cached myfile.php
  $ git commit -m "Removing a file"

There are 3 Comments

do you have a pre-commit hook?

i have a php pre commit hook that was breaking it


exec("php -l " . escapeshellarg($file), $lint_output, $return);

$return = 0;
if (file_exists($file)) {
exec("php -l " . escapeshellarg($file), $lint_output, $return);

Yes, there's a good chance I had a pre-commit hook when I ran into this. Most of my PHP projects do a "php -l" before the commit -- apparently just like you!


Yes, per the comment above, adding the check for file existence to my pre-commit hook script removed this error.

Here is where my pre-commit hook is :