我如何列出根上的git子树? [英] How can I list the git subtrees on the root?

查看:85
本文介绍了我如何列出根上的git子树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,您可以执行 git remote --verbose ,git会显示您在项目中拥有的所有遥控器, git branch 将显示所有分支并发出当前分支的信号,但是如何列出所有子树,而没有任何破坏性命令? git subtree 会给出使用示例,但不会列出任何内容。子树只有 add pull , push split merge

解决方案

没有任何明确的方法可以做到这一点(至少现在是这样),唯一可用的命令在这里列出(正如你自己提到的,但是这里是未来寻求者的参考):
https://github.com/git/git/blob/master/contrib/subtree/git -subtree.txt



我经历了代码(基本上所有这些机制都是一个大的shell脚本文件),所有的跟踪都是通过提交消息完成的,所以所有的函数都使用 git log 机制以及大量的 grep -ing来定位它自己的数据。



由于子树必须在存储库的根文件夹中具有相同名称的文件夹,因此您可以运行它以获取所需的信息(在Bash shell中):

  git log | grep git-subtree-dir | tr -d''| cut -d:-f2 |排序| uniq 

现在,这并不检查文件夹是否存在(您可以删除它并子树机制将不知道),所以下面是如何只列出现有的子树,这将在存储库中的任何文件夹中工作:

  git log | grep git-subtree-dir | tr -d''| cut -d:-f2 |排序| uniq | xargs -I {} bash -c'if [-d $(git rev-parse --show-toplevel)/ {}];然后echo {}; fi'

如果你真的想做到这一点,请将它推荐给Git人员以包含在下一个版本中:)

For example, you can do a git remote --verbose and git will show all the remotes you have on your project, git branch will show all the branches and signal the current branch, but how to list all subtrees, without any destructive command? git subtree will give the usage examples, but won't list anything. subtree only have add,pull,push,split,merge.

解决方案

There isn't any explicit way to do that (at least, for now), the only available commands are listed here (as you noted yourself, but here's a reference for future seekers): https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt

I went through the code (basically all this mechanism is a big shell script file), all of the tracking is done through commit messages, so all the functions use git log mechanism with lots of grep-ing to locate it's own data.

Since subtree must have a folder with the same name in the root folder of the repository, you can run this to get the info you want (in Bash shell):

git log | grep git-subtree-dir | tr -d ' ' | cut -d ":" -f2 | sort | uniq

Now, this doesn't check whether the folder exist or not (you may delete it and the subtree mechanism won't know), so here's how you can list only the existing subtrees, this will work in any folder in the repository:

 git log | grep git-subtree-dir | tr -d ' ' | cut -d ":" -f2 | sort | uniq | xargs -I {} bash -c 'if [ -d $(git rev-parse --show-toplevel)/{} ] ; then echo {}; fi'

If you're really up to it, propose it to Git guys to include in next versions:)

这篇关于我如何列出根上的git子树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆