bgusach
bgusach

Reputation: 15205

Git alias in nested command

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

Upvotes: 1

Views: 1745

Answers (1)

mkrnr
mkrnr

Reputation: 900

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.

Upvotes: 6

Related Questions