git 在(包含)提交之后登录? (与--图)

git log after(contains) commit? (with --graph)

我知道

有没有办法在概念上将前一个命令的输出定向到后者?
git branch --contains <REVISION> | git log --branches=

目标是在使用git log --decorate --graph --oneline [OTHER_OPTIONS]

时过滤分支

谢谢~

Is there any way to conceptually direct output of [one] command [as arguments to another]?

shell(shbash 或您使用的任何 shell 命令解释器)通常有一种方法可以做到这一点。

有两种常见的拼写,一种使用反引号,这对于非常短的项目很方便,另一种使用 $(...),通常更好,因为它可以正确嵌套。

git branch --contains 的问题是它的输出格式不正确:如果它打印的分支名称之一包含给定的提交,它会打印 * 当前分支。您必须做一些事情来删除星号,或者使用更面向命令的命令。后者通常更好,但要求您的 Git 不能太旧(2.6 或更高版本):将 git branch --contains <rev> 替换为 git for-each-ref --contains=<rev> --format='%(refname)' ref/heads

现在,您不能将其转换为 --branches=git log 的一组 glob 模式,但您 不需要 ,因为 --branches=<glob> 所做的只是告诉 git log 从匹配 refs/heads/<glob> 的引用开始,而 git for-each-ref 已经将生成此类引用的完整列表。因此,您需要做的就是将完整的参考列表传递给 git log.

因为 shells 也将 $name 扩展为一个包含一些名称的变量,我将在下面使用它而不是 <...>,否则它是模棱两可的(它可能意味着一个文字小于号等)。这给出:

git log $log_args $(git for-each-ref --contains=$rev --format='%(refname)')

如果您的 git for-each-ref 太旧而无法处理 --contains,您必须使用 git branch --contains 并去掉前两列,例如:

git log $log_args $(git branch --contains $rev | cut -c3-)

这有一个缺陷,因为 git branch 没有在分支名称前加上 refs/heads。如果你有一个名为 xyzzy and 的分支,一个名为 also 的标签 xyzzygit branch 知道使用branch 名称,--branches=xyzzy 会知道使用 branch 而不是 tag , 但只需在命令行上命名 xyzzy 即可获得标签,因为通常标签的优先级高于分支。 (参见 the gitrevisions documentation, which lists the six steps taken to resolve a name: try it as a tag is step 3 and try it as a branch is step 4. The tag has higher priority.) To fix that—to avoid this xkcd——你需要再想一想:

git log $log_args $(git branch --contains $rev | cut -c3- | sed s,^,refs/heads,)

例如。 (当然,另请参阅 this xkcd。)