如何在 git 的历史记录中查找包含提交的所有引用

2024-01-15

假设你在 git 中有以下结构

    A <-- refs/heads/somebranch
    |
    B 
    | \
    C  D <-- refs/tags/TAG1
    |  |
    E  F
    |  | \
    G  H  I <-- refs/heads/branch1                
    |
    J <-- refs/heads/master

现在我想找到所有包含提交的引用B在他们的历史中。

所以如果我能做到就好了

$ git refs --contains B
refs/tags/TAG1
refs/heads/branch1
refs/heads/master

我查看了 git decumentation 并发现git branch -a --contains <commit_id>其中列出了包含以下内容的所有分支commit_id.

$ git branch -a --contains 4af9822
  master
  remotes/origin/someBranch
  ...

我找到了命令git tag --contains 9338f2d

$ git tag --contains 9338f2d
  someTag
  anotherTag
  ...

我当然可以做这样的事情

$ git branch -a --contains 4af9822 && git tag --contains 9338f2d

但是有没有一个命令可以一次打印所有引用?


为了补充 torek 的答案,git 2.7(2015 年第四季度)将提供更完整的版本git for-each-ref http://git-scm.com/docs/git-for-each-ref,现在支持--contains

git for-each-ref --contains <SHA1>

See commit 4a71109 https://github.com/git/git/commit/4a71109aa442ba1a7045d36f6b148113c95ffc48, commit ee2bd06 https://github.com/git/git/commit/ee2bd06b0f735a00ce0216ca1d3391b13722d987, commit f266c91 https://github.com/git/git/commit/f266c9163b34ec55e453d27e1ed246d67ee3ced0, commit 9d306b5 https://github.com/git/git/commit/9d306b5a6077f026291df3c4a5968eaf95a92417, commit 7c32834 https://github.com/git/git/commit/7c32834813bd6aee5ce5b2c4131d9f34249bc9e3, commit 35257aa https://github.com/git/git/commit/35257aa01203bae74f9fb856fb02c10c4b3836e6, commit 5afcb90 https://github.com/git/git/commit/5afcb90560586765bf21fb09959a8b4497804639, commit d325406 https://github.com/git/git/commit/d325406ef2f3c819d02ac838fb2a3f8e021d08ae, commit 6841104 https://github.com/git/git/commit/68411046b5067de9c378d1f58313f2fae288286c, commit b2172fd https://github.com/git/git/commit/b2172fdf702426cb4eba093b5504d0a0e9e59746, commit b2172fd https://github.com/git/git/commit/b2172fdf702426cb4eba093b5504d0a0e9e59746, ..., commit b2172fd https://github.com/git/git/commit/b2172fdf702426cb4eba093b5504d0a0e9e59746 (07 Jul 2015), and commit af83baf https://github.com/git/git/commit/af83bafa4867ba16368e58f36e8311e9591e68f4 (09 Jul 2015) by Karthik Nayak (KarthikNayak) https://github.com/KarthikNayak.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit 9958dd8 https://github.com/git/git/commit/9958dd8685a0a8b3d6ecdd07e35d8ecb22b304a7, 05 Oct 2015)

一些功能来自“git tag -l" and "git branch -l“ 已做出 有空 ”git for-each-ref“以便最终统一 后续实施可以在所有三个之间共享 系列或两个。

* kn/for-each-tag-branch:
  for-each-ref: add '--contains' option
  ref-filter: implement '--contains' option
  parse-options.h: add macros for '--contains' option
  parse-option: rename parse_opt_with_commit()
  for-each-ref: add '--merged' and '--no-merged' options
  ref-filter: implement '--merged' and '--no-merged' options
  ref-filter: add parse_opt_merge_filter()
  for-each-ref: add '--points-at' option
  ref-filter: implement '--points-at' option  

请注意,从 Git 2.13(2017 年第 2 季度)开始,git for-each-ref --no-contains <SHA1>终于支持了!

See commit 7505769 https://github.com/git/git/commit/75057691beb804e804df21992ae55d50ffc36f92, commit 783b829 https://github.com/git/git/commit/783b829287952ec42bf89d9ca42fc6c51d7d0143, commit ac3f5a3 https://github.com/git/git/commit/ac3f5a346860b824e083c5d305757c3260565475, commit 1e0c3b6 https://github.com/git/git/commit/1e0c3b680c6e7b37fc51bd69a410af01897a4f94, commit 6a33814 https://github.com/git/git/commit/6a338149f623f493525324bc0f8d7bb9257cb840, commit c485b24 https://github.com/git/git/commit/c485b24c427254fe36c2c6cc970519b797abd6bc, commit eab98ee https://github.com/git/git/commit/eab98ee5ab84def96012f115a8e10571c6e24e4e, commit bf74804 https://github.com/git/git/commit/bf748049f53cea3662b02d87cc91d44a0164e588 (24 Mar 2017), commit 7ac04f1 https://github.com/git/git/commit/7ac04f1398c4e854cb585bd289ee4fe921984bbd, commit 682b29f https://github.com/git/git/commit/682b29f90d7e049c24f3821d49599dceb4aeb758, commit 4612edc https://github.com/git/git/commit/4612edc639e8c7c15420960a92efa609e92ab9a7, commit b643827 https://github.com/git/git/commit/b643827b9443deadaa5804998116107953f8b42f (23 Mar 2017), and commit 17d6c74 https://github.com/git/git/commit/17d6c744dc0d5ed4cd0f228da14239ea2654f05b, commit 8881d35 https://github.com/git/git/commit/8881d35cace41604dba72c1b6b5ab5a59e0c2b94, commit b084060 https://github.com/git/git/commit/b084060921d6403164e8dee506de787d017569c3, commit 0488792 https://github.com/git/git/commit/0488792d2e56bfe38be6ea7f5456bd3286c807b8 (21 Mar 2017) by Ævar Arnfjörð Bjarmason (avar) https://github.com/avar.
(Merged by Junio C Hamano -- gitster -- https://github.com/gitster in commit d1d3d46 https://github.com/git/git/commit/d1d3d46146e1256efe8ad2a2bb0dd877a738c07d, 11 Apr 2017)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 git 的历史记录中查找包含提交的所有引用 的相关文章

  • Git 存储库错误并显示消息,它不是存储库...但它是

    我有一个 git repo 去年我一直在同一个盒子上使用 今天我跑步git status并得到错误消息 fatal Not a git repository or any parent up to mount parent home Sto
  • 如何保持 git 存储库的公共和私有版本同步?

    我正在 Github 上发布一个开源 Rails 应用程序 可能是 MIT 许可证 我还想维护一个项目的私人分支 分支 我们将使用它作为付费服务的一部分 在这种情况下组织存储库的最佳方式是什么 而且 当我有两个项目的更新时 如何保持项目同步
  • 在单独的终端屏幕上显示 git diff 和 git log 输出

    设置新的开发环境后 我遇到了一个奇怪的 git 行为 我不记得过去见过 我习惯于git diff and git log在终端中创建一个新屏幕并在其中显示其输出 什么less默认情况下 我用它作为我的寻呼机 然后我可以退出并返回到之前的终端
  • Git Add - 致命:添加文件失败

    我的 git cmd exe 窗口如下所示 git add NextFolder error unable to create temporary file No such file or directory error NextFolde
  • 使用 git filter-branch 然后 git push --force 清除大文件后,远程(Gitlab)上的 Git 存储库大小仍然很大

    我已按照 Gitlab 文档中有关 使用 Git 减少存储库大小 的说明进行操作 通过从历史记录中清除大文件 https docs gitlab com ee user project repository reducing the rep
  • 在功能分支上运行测试

    我有一个构建配置 其中包含连接到 git 分支的测试 VCS 根dev 3 个构建步骤和 1 个触发器 这些是我的构建步骤 构建测试 运行测试 构建和部署 我想为分支运行所有这些构建步骤dev但只有其中两个 构建和运行测试 用于分支匹配fe
  • 如何设置“阅读文档”以使 Sphinx autodoc 选项发挥作用?

    我的项目不是使用 autodoc 构建的 我遇到了关于我的项目未在 autodoc 中构建的常见问题 https read the docs readthedocs org en latest faq html my project isn
  • 返回到 Github Desktop 中的上一个提交

    我正在尝试使用 GitHub Desktop 即 GUI 应用程序 而不是命令行 返回到先前的提交 在同一分支上 我认为这是一个核心功能 因为它是首先使用源代码控制的主要原因 我可以看到可以恢复提交 但这并不是我真正想要的 因为它创建了一个
  • 我可以获取两次提交之间 git 子文件夹中已更改文件的列表吗?

    我有一个包含许多文件夹的 git 存储库 我需要找出在两次提交之间这些文件夹之一中的哪些文件发生了更改 有没有一个好的方法来做到这一点 我想你可以坚持走最后的路git diff git diff HEAD HEAD special fold
  • 如何将更改提交到另一个预先存在的分支

    我刚刚对一个分支进行了更改 如何将更改提交到另一个分支 我正在尝试使用 git checkout the commmit to the changed branch b the other branch 但是 我认为这不是正确的做法 因为在
  • 使用 SourceTree 克隆存储库

    有人可以给我一个简单的使用 SourceTree 克隆存储库的快速演练吗 在书签中 我单击克隆存储库 对于源路径 我粘贴如下所示的 URL 电子邮件受保护 cdn cgi l email protection 客户端 应用程序名称 ios
  • git 的精简包是什么?

    我还没有找到太多关于瘦包的信息 并且手册页的信息对此相当含糊 我知道这与连接速度慢有关 但是什么是 连接速度慢 它的优点和缺点是什么 什么时候应该使用它 什么时候不应该使用它 根据记录 手册页 index pack https www gi
  • Git子模块绝对工作树路径配置

    这是我的子模块redmine 仪表板配置文件 子模块配置文件 core repositoryformatversion 0 filemode true bare false logallrefupdates true worktree Us
  • Jenkins groovy - 如何从最新提交中检索标签?

    从中获取最新提交branchName 我们运行下面的代码 treeMapData git branch branchName credentialsId credential url gitLabServer projectName rep
  • 将两个单独的功能分支合并到同一个主分支中[重复]

    这个问题已经存在了 我们正在努力发布 2 个远程功能分支 F2 和 F3 我们如何处理F3来创建发布 提案1 简单地合并F3进入开发 提案2 第一次合并开发进入F3 包括F2的变化 然后合并进入发展 这两种方法之间有什么实际差异 是否有客观
  • 将远程更改合并到非当前分支的分支中

    我有多个分支 我想将远程更改合并到一个分支中不是我当前的分支 例如 git merge remote branch some other branch 仅当本地分支可以快速转发到远程头时 这才是可行的 在任何分支中 要从源获取远程分支并更新
  • 更改 Windows 安装的 Git Bash 中 ~ 目录的位置

    我什至不确定我问的是正确的问题 让我解释一下我的情况 这是关于 Windows 7 上的 Git 我的公司在网络驱动器上设置 Windows 用户目录 而不是在本地硬盘驱动器上 用于备份和超出本问题范围的其他目的 我无法改变这项政策 然而
  • 如何 git checkout 提交并将子模块更新到该提交?

    我正在克隆一个带有子模块的项目并恢复到大约一年前的提交 git clone recursive branch 5 6 https codereview qt project org pyside pyside setup cd pyside
  • 设置单独的遥控器以仅推送和拉动子文件夹

    假设我有两个存储库 repo A and repo B 其中包含一个文件夹 其中的代码与存储库 A 中的代码类似 这实际上如何发生并不重要 但是好吧 让我们假设我刚刚从 A 复制了内容 现在我想要以下内容 就像我在 repo A 中习惯的那
  • 将代码从没有权限的存储库推送到私有存储库?

    我有一个来自外部存储库 我们称之为 ExRepo 的文件夹 我没有任何推送权限 我有一个名为 MyOwnRepo 的个人存储库 如何获取 ExRepo 并将其合并到 MyOwnRepo 中 我已经尝试过这个 C Users

随机推荐