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 )
where ~/gitstatn
contains:
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
这足以满足我的需求。
Sometimes Git can be rather tedious if there are many similar filenames. For instance:
# 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")
I'd much rather type git diff 1
instead of git diff FormRegion1.Designer.cs
(even with tab-completion). Currently I'm doing something like this:
git diff $( ~/gitstatn 1 )
where ~/gitstatn
contains:
git status -s | head -n$1 | tail -n1 | cut -c 4-
which is no better.
How can I type something like git add 3
or git diff 5
and mean git add FormRegion1.resx
or git diff OptionPage.cs
, respectively?
I'm using Cygwin on Windows.
.
Edit - As per adymitruk's suggestion, I've settled on aliasing gpick
to a script:
#!/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
which is sufficient for my needs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请改用 git ls-files。你不需要剪。您将需要编写脚本。您可以使用 -p 参数进行添加,但我喜欢您的脚本。让脚本接受您想要的命令:
您可能也想对未跟踪的文件执行某些操作。
希望这有帮助
Use git ls-files instead. You won't need cut. You will need to script. You could use the -p parameter for add, but I like your script. make the script accept the command you want:
You may want to do something for untracked files too.
Hope this helps
查看 git-number。我专门为此用例编写了它 。
Check out git-number. <plug>I wrote it specifically for this use case</plug>.