1

I know how to create simple aliases, but there is this very useful command to unstage deleted files from disk that I cannot make it work.

git rm $(git ls-files --deleted)

(from here Removing multiple files from a Git repo that have already been deleted from disk)

I have tried with:

git config --global alias.cleandeleted 'rm $(git ls-files --deleted)'

But when I write:

git cleandeleted

I get the following error:

error: unknown option `deleted)'
usage: git rm [options] [--] <file>...

    -n, --dry-run         dry run
    -q, --quiet           do not list removed files
    --cached              only remove from the index
    -f, --force           override the up-to-date check
    -r                    allow recursive removal
    --ignore-unmatch      exit with a zero status even if nothing matched
Community
  • 1
  • 1
bgusach
  • 14,527
  • 14
  • 51
  • 68

1 Answers1

6

The problem is the $(...). As you have defined it, git only handles git intern commands and doesn't know how to deal with $(...).

There is a trick to make you command work:

git config --global alias.cleandeleted '!git rm $(git ls-files --deleted)'

Because of the ! the alias works as if the command was given directly to the command line.

mkrnr
  • 842
  • 8
  • 17