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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.