解析“git submodule foreach ‘git status’”的输出

发布于 2024-12-09 04:12:47 字数 3719 浏览 0 评论 0原文

我有一个包含许多子模块的 Git 超级项目。我希望能够浏览子模块并运行 git status ,以便我可以快速查看每个子模块所在的分支以及是否存在未提交的更改。但是,当我运行 git submodule foreach 'git status' 时,很难解析,而且我无法判断它正在报告哪个子模块的状态。它似乎只是吐出了我的 %PATH% 变量(我在 Windows 上使用 msysGit)。我的输出与此处显示的类似:

Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
nothing to commit (working directory clean)
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# Your branch is ahead of 'FlashDrive/My_Branch' by 10 commits.
#
nothing to commit (working directory clean)
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# 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:   MyApp/Win32/Release/MyApp.exe
#   modified:   MyApp/WinCe600 (ARMV4I)/Release/MyApp.exe
#   modified:   MyApp/WinCe600 (ARMV4I)/Release/Startup.exe
#
no changes added to commit (use "git add" and/or "git commit -a")
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# Your branch is ahead of 'FlashDrive/My_Branch' by 8 commits.
#
nothing to commit (working directory clean)

如您所见,这很难浏览(尤其是当输出被包装时)并查看“git status”的输出。此外,未显示每个子模块的名称,因此我无法知道输出的每个部分引用的是哪个子模块。

任何帮助表示赞赏!谢谢!

I have a Git super project with many submodules. I'd like to be able to go through the submodules and run git status so that I can quickly see which branch each submodule is on and whether there are uncommitted changes. However when I run git submodule foreach 'git status' it is difficult to parse and I can't tell which submodule it's reporting the status for. It appears to just spew out my %PATH% variable (I'm using msysGit on Windows). My output appears similar to that shown here:

Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
nothing to commit (working directory clean)
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# Your branch is ahead of 'FlashDrive/My_Branch' by 10 commits.
#
nothing to commit (working directory clean)
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# 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:   MyApp/Win32/Release/MyApp.exe
#   modified:   MyApp/WinCe600 (ARMV4I)/Release/MyApp.exe
#   modified:   MyApp/WinCe600 (ARMV4I)/Release/Startup.exe
#
no changes added to commit (use "git add" and/or "git commit -a")
Entering 'C:\Program Files\Git/libexec/git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\libexec\git-core;C:\Program Files\Git\bin;c:\Documents and Settings\username\My Documents\LinuxHome\bin;.;C:\Program Files\Git\local\bin;C:\Program Files\Git\mingw\bin;C:\Program Files\Git\bin;c:\WINDOWS\system32;c:\WINDOWS;c:\WINDOWS\System32\Wbem;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\WINDOWS\system32\WindowsPowerShell\v1.0;c:\Program Files\Intel\WiFi\bin\;c:\Program Files\Windows Imaging\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Files\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\TortoiseSVN\bin'
# On branch My_Branch
# Your branch is ahead of 'FlashDrive/My_Branch' by 8 commits.
#
nothing to commit (working directory clean)

As you can see, this is quite difficult to glance at (especially when the output is wrapped) and see what the output of 'git status'. In addition the name of each submodule is not shown so I have no way of knowing which submodule each section of output refers to.

Any help is appreciated! Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2024-12-16 04:12:47

例如,您没有准确提及您想要显示的内容...

 git submodule foreach -q git ls-files -m 

将在仅显示修改后的文件方面大有帮助。其他选项包括

 git submodule foreach -q git diff --shortstat --staged # staged
 git submodule foreach -q git diff --shortstat          # unstaged
 git submodule foreach -q git diff --shortstat HEAD     # staged AND unstaged

您可以按照以下方式编写一个愚蠢的小脚本:

 #!/bin/sh
 echo "$(basename .) $(git branch)"

使用子模块目录名称来显示您想要的内容以便于识别。

如果您无法根据上述想法解决问题:不要去尝试解析不是为机器消耗而设计的输出。 Git 有一组非常丰富的子命令,可以更好地帮助您。

You fail to mention exactly what it is you want shown...

 git submodule foreach -q git ls-files -m 

would go a long way at showing just the modified files, for example. Other options include

 git submodule foreach -q git diff --shortstat --staged # staged
 git submodule foreach -q git diff --shortstat          # unstaged
 git submodule foreach -q git diff --shortstat HEAD     # staged AND unstaged

You could write a silly small script in the following vein:

 #!/bin/sh
 echo "$(basename .) $(git branch)"

To show just what you want using the submodule directory name for easier identification.

In case you couldn't work it out from the above ideas: don't go and try to parse output that wasn't designed for machine consumption. Git has a very rich set of subcommands that can help you out in a better way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文