假设我有3个文件处于 git状态
git status
modified: app/views/index.html.erb
modified: GEMFILE
modified: config/routes.rb
假设我要检查列表中第一名的git-diff
git diff app/views/index.html.erb
问题是:有什么方法可以选择git-status列表(在键盘上)的第一项或最后一项,以避免臭名昭著的复制/粘贴?
答案 0 :(得分:4)
您可以使用--porcelain
中的git status的man git-status
选项:
--porcelain[=<version>]
Give the output in an easy-to-parse format for scripts. This is similar to the short output, but will remain stable across Git versions and
regardless of user configuration. See below for details.
然后得到第一个可能是这样的(如果您的需求不同,请适应它):
git diff $(git status --porcelain | cut -b4- | head -1)