【问题标题】:Bash - Get only directory names from git status [duplicate]Bash - 仅从 git status 获取目录名称 [重复]
【发布时间】:2019-09-17 23:07:50
【问题描述】:

我只需要 git status 中的目录名称。当我使用git status -s 时,作为一种简短形式,我得到以下输出。

M stack/pipeline.yaml
?? stackother/

而我只需要 stack/stackother/ 作为列表或作为输出,我可以通过管道传递到下一组命令。

基本上,我需要新创建的目录或文件中有一些更改的目录。有没有办法使用 git 来做到这一点?

编辑: 我实际上需要每个更改文件的父目录,例如以下示例:

stack/pipeline.yaml
stack/newstack/master-pipeline.yaml
stack/newstack/test/test11.txt
stack/newstack/test/tester.txt

我明白了

stack
stack/newstack
stack/newstack/test

而不是

stack

因此,这个问题不是链接问题的重复。对于基本示例,瓷器的答案有效,但要进行更多更改,我必须执行 git status -s -uall 并处理此输出。

【问题讨论】:

标签: bash git shell directory git-status


【解决方案1】:

你可以这样做:

git status -s -uall | awk '{print $2}' | xargs -L1 dirname| uniq

【讨论】:

  • 我明白你在这里做了什么,但不知何故在 M 字符之前有一个空格,它输出 M 作为第一行的输出,第二行很好
  • awk '{print $2}' 代替cut -d ' ' -f 2 怎么样?
  • git status -s -uall |切-c 4- | xargs -L1 目录名,这对我有用。另外, git status --porcelain | awk '{打印 $2}' | xargs -L1 dirname 请更新您的答案,以便我接受它:)
  • 用 awk 更新 :-)
  • 实际上,带有瓷器的命令不适合我的需要,因为我需要每次文件更改的父目录,而对于我给定的示例,瓷器的答案也很有效。我已经更新了问题,因为它被标记为重复,而不是。 git status -s -uall | awk '{print $2}' | xargs -L1 dirname| uniq 做我需要的。可能会相应地更新答案。
猜你喜欢
  • 2022-11-04
  • 1970-01-01
  • 2010-09-06
  • 1970-01-01
  • 2015-09-24
  • 1970-01-01
  • 2015-09-12
  • 1970-01-01
  • 2019-12-17
相关资源
最近更新 更多