git-diff 在另一个目录中

发布于 2024-08-31 06:48:34 字数 503 浏览 1 评论 0原文

我目前正在编写一个小 zsh 函数,它检查我所有的 git 存储库,看看它们是否脏,然后打印出需要提交的存储库。到目前为止,我已经发现找出 git 存储库的干净/脏状态的最快方法是通过 git-diff 和 git-ls-files :

if ! git diff --quiet || git ls-files --others --exclude-standard; then
  state=":dirty"
fi

我有有两个问题要问你们:

  1. 有谁知道有一种更快、更有效的方法来检查 git 存储库中的文件更改/添加吗?
  2. 我希望为我的 zsh 函数提供一个文件路径(例如 ~/Code/git-repos/)并检查其中的所有存储库。有没有办法不必 cd 进入每个目录并运行这些命令?像 git-diff --quiet --git-dir="~/Code/git-repos/..." 之类的东西会很棒。

谢谢! :)

I'm currently writing a little zsh function that checks all of my git repositories to see if they're dirty or not and then prints out the ones that need a commit. Thus far, I've figured out that the quickest way to figure out a git repository's clean/dirty status is via git-diff and git-ls-files:

if ! git diff --quiet || git ls-files --others --exclude-standard; then
  state=":dirty"
fi

I have two questions for you folks:

  1. Does anyone know of a quicker, more efficient way to check for file changes/additions in a git repo?
  2. I want my zsh function to be handed a file path (say ~/Code/git-repos/) and check all of the repositories in it. Is there a way to do without having to cd into each directory and run those commands? Something like git-diff --quiet --git-dir="~/Code/git-repos/..." would be fantastic.

Thanks! :)

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

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

发布评论

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

评论(1

柳絮泡泡 2024-09-07 06:48:34

如果 $DIR 保存您的目录名称并且它是标准布局(即 .git 目录是 $DIR/.git),则 git --git-dir $DIR/.git --work-tree $DIR status -s -uno 将列出所有具有未提交更改的文件。检查列表是否为空应该会给你你想要的。

If $DIR holds your directory name and it's a standard layout (i.e. the .git dir is $DIR/.git), then git --git-dir $DIR/.git --work-tree $DIR status -s -uno will list all the files that have uncommitted changes. Checking if the list is empty should give you what you want.

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