Search code examples
gitwildcardrm

How to git rm a file containing *


As an accident of typing, I've ended up with a file in the repo ending with the * character. I'm using Bash.

Let's call the file "bin/abc*". Also there are files bin/xyz and others beginning with bin/abc such as bin/abc1 and bin/abc2.

I've tried a whole bunch of tactics, including:

  1. $ git rm bin/abc\*, which deletes all the other files, but not the "bin/abc*";
  2. $ git rm bin/abc[*], which deletes all the other files, but not the "bin/abc*";
  3. $ git rm bin/abc\\*, which recognises no files;
  4. $ git rm bin/abc[^a-z], which recognises no files;
  5. "git rm "bin/abc*", which deletes all the other files, but not the "bin/abc*";

I've run out of ideas.


Solution

  • Assuming the file is tracked, put the filename in quotes, e.g.

    git rm "bin/abc*"
    

    If it isn't tracked, use rm instead of git rm:

    rm "bin/abc*"