Getting "git rm" to work

Posted on August 5th, 2010 by David Luhman and tagged .

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 (http://cheat.errtheblog.com/s/git) described this as "Commit the absence of myfile.txt to the project"


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

Comments

Re: Getting "git rm" to work

do you have a pre-commit hook?

i have a php pre commit hook that was breaking it

changed

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

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

Comment by Anonymous on Mar 23rd, 2011 at 7:06 pm

Pre-commit hook and "git rm"

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!

Thanks!

Comment by David Luhman on Apr 18th, 2011 at 2:52 pm

Add check for file existence

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 :

/.git/hooks/pre-commit-php-l.php

Comment by David Luhman on Nov 21st, 2011 at 2:56 pm

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options