Git命令,按状态输出索引引用文件?

时间:2011-06-08 15:06:36

标签: git alias

如果有许多类似的文件名,Git可能会相当繁琐。例如:

# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       modified:   FormRegion1.Designer.cs
#       modified:   FormRegion1.cs
#       modified:   FormRegion1.resx
#       modified:   OptionPage.Designer.cs
#       modified:   OptionPage.cs
#       modified:   OptionPage.resx
#
no changes added to commit (use "git add" and/or "git commit -a")

我更愿意输入git diff 1而不是git diff FormRegion1.Designer.cs(即使使用制表符完成)。目前我正在做这样的事情:

git diff $( ~/gitstatn 1 )

~/gitstatn包含:

git status -s | head -n$1 | tail -n1 | cut -c 4-

哪不好。

如何分别输入git add 3git diff 5以及git add FormRegion1.resxgit diff OptionPage.cs

我在Windows上使用Cygwin。

编辑 - 根据 adymitruk 的建议,我已经确定将gpick别名化为脚本:

#!/usr/bin/bash

if [ -z $1 ]; then
    echo 'no git command specified'
elif [ -z $2 ]; then
    git $1
else
    git $1 $( git ls-files -m | head -n$2 | tail -n1 )
fi

这足以满足我的需求。

2 个答案:

答案 0 :(得分:0)

改用git ls-files。你不需要削减。你需要编写脚本。您可以使用-p参数进行添加,但我喜欢您的脚本。让脚本接受你想要的命令:

gpick diff 1
gpick add 3

您可能也希望为未跟踪的文件执行某些操作。

希望这有帮助

答案 1 :(得分:0)

结帐git-number。 &lt; plug&gt;我专门针对此用例编写了它&lt; / plug&gt;。