有時如果有很多類似的文件名,Git可能會很乏味。例如: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 3
或git diff 5
的東西,並且分別代表git add FormRegion1.resx
或git 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
這足以滿足我的需求。
我只是使用複製和粘貼。 – 2011-06-08 16:24:39
等一下,所以你寧願記住文件列表輸出中一個你甚至沒有看到的文件的序號(大概在新文件出現時改變它的順序並重新排序),而不是使用tab-completion實際上是通過名稱來調用文件的? – 2011-06-08 19:39:23
@Dan:不,我寧願說'git status'後面跟着'git diff x'。 Tab完成是比較單調乏味的IMO,特別是在一個大小相近的文件系統上。這可能是一個小生意,但我覺得它對我自己來說非常有價值。 – wes 2011-06-08 20:19:13