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
4

1 回答 1

5

问题是$(...). 正如您所定义的,git 只处理 git intern 命令,不知道如何处理$(...).

有一个技巧可以让你命令工作:

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

由于!别名的工作方式就好像命令直接提供给命令行一样。

于 2013-05-27T17:16:01.593 回答