2013-05-27 63 views
0

我知道如何创建简单的别名,但是有一个非常有用的命令来从磁盘中取消删除的文件,我无法使其工作。嵌套命令中的Git别名

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

(从这里Removing multiple files from a Git repo that have already been deleted from disk

我曾尝试用:

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

但是,当我写:

git cleandeleted 

我收到以下错误:

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 

回答

3

问题是$(...)。正如你所定义的,git只处理git实习生命令,并不知道如何处理$(...)

有一招,让你指挥工作:

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

因为!别名,工作起来就像直接给到命令行命令。

+0

工程就像一个魅力!非常感谢 – bgusach

+0

不客气! :-) – mkrnr