git-diff 在另一个目录中
我目前正在编写一个小 zsh 函数,它检查我所有的 git 存储库,看看它们是否脏,然后打印出需要提交的存储库。到目前为止,我已经发现找出 git 存储库的干净/脏状态的最快方法是通过 git-diff 和 git-ls-files :
if ! git diff --quiet || git ls-files --others --exclude-standard; then
state=":dirty"
fi
我有有两个问题要问你们:
- 有谁知道有一种更快、更有效的方法来检查 git 存储库中的文件更改/添加吗?
- 我希望为我的 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:
- Does anyone know of a quicker, more efficient way to check for file changes/additions in a git repo?
- 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 likegit-diff --quiet --git-dir="~/Code/git-repos/..."
would be fantastic.
Thanks! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果
$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
), thengit --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.