使用 Git 对所有远程分支进行头提交

发布于 2024-09-26 16:43:20 字数 437 浏览 9 评论 0原文

我知道如何列出远程分支

$ git branch -a

我知道如何找到当前分支的头提交哈希

$ git rev-parse HEAD

但我不确定如何列出所有远程分支的所有头提交哈希。这很接近我想要的,但是它们的顺序是什么?

$ git rev-parse --remotes
4b9f7128e9e7fa7d72652ba49c90c37d0727123d
4ebab9616fac6896b7827e8502b4dc7c5aac6b5b
ea7a5fab4a757fb0826253acf1fe7d8c546c178e
...

理想情况下,我想要一个分支名称提交哈希对的列表,甚至想要一种将远程分支名称传递给 git rev-parse HEAD 的方法

I know how to list the remote branches

$ git branch -a

And I know how to find the head commit hash of my current branch

$ git rev-parse HEAD

But I'm not sure how to list all the head commit hashes for all the remote branches. This is close to what I want but what order are they in?

$ git rev-parse --remotes
4b9f7128e9e7fa7d72652ba49c90c37d0727123d
4ebab9616fac6896b7827e8502b4dc7c5aac6b5b
ea7a5fab4a757fb0826253acf1fe7d8c546c178e
...

Ideally, I'd like a list of branch-name commit-hash pairs or even a way to pass a remote branch name to git rev-parse HEAD

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

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

发布评论

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

评论(3

童话 2024-10-03 16:43:20

使用

git branch -r -v --no-abbrev

忽略带有提交消息的部分或

git show-ref

过滤以 refs/remotes 开头的结果。

Use either

git branch -r -v --no-abbrev

and ignore part with commit message or

git show-ref

and filter results starting with refs/remotes.

丘比特射中我 2024-10-03 16:43:20

我知道这是旧的并且已得到解答,但我认为 git ls-remote 也适用于此。

git ls-remote --heads origin

fcce961b46784fae13be8a30c2622ddd34d970ec        refs/heads/develop
9da7bb692a72235451706f24790a3f7a100a64e2        refs/heads/feature-netty-testing
86020c50d86691caecff4a55d3b1f2f588f6291d        refs/heads/javafx-testing
871d715e5c072b1fbfacecc986f678214fa0b585        refs/heads/master
7ed641c96d910542edeced5fc470d63b8b4734f0        refs/heads/orphan-branch

I know this is old and answered, but I think git ls-remote would work for this too.

git ls-remote --heads origin

fcce961b46784fae13be8a30c2622ddd34d970ec        refs/heads/develop
9da7bb692a72235451706f24790a3f7a100a64e2        refs/heads/feature-netty-testing
86020c50d86691caecff4a55d3b1f2f588f6291d        refs/heads/javafx-testing
871d715e5c072b1fbfacecc986f678214fa0b585        refs/heads/master
7ed641c96d910542edeced5fc470d63b8b4734f0        refs/heads/orphan-branch
送你一个梦 2024-10-03 16:43:20

您可以使用 git rev-parse 来实现此目的。它可以接受任何看起来像提交的东西,并返回该提交的完整 SHA1 哈希值。

例如,获取HEAD的SHA1:

git rev-parse HEAD

获取master的SHA1:

git rev-parse master

获取origin/trunk的SHA1:

git rev-parse origin/trunk

获取 master的SHA1:所有远程头的 SHA1(这只是实现此目的的众多方法之一,当然不是最好的方法):

 git branch -r | cut -d' ' -f 3 | while read remote; do
   echo ${remote} `git rev-parse ${remote}`
done

You can use git rev-parse for this. It can take anything which looks even remotely like a commit and returns the full SHA1 hash for that commit.

For example, to get the SHA1 of HEAD:

git rev-parse HEAD

To get the SHA1 of master:

git rev-parse master

To get the SHA1 of origin/trunk:

git rev-parse origin/trunk

To get the SHA1s of all remote heads (this is just one of many ways to do this, and certainly not the best one):

 git branch -r | cut -d' ' -f 3 | while read remote; do
   echo ${remote} `git rev-parse ${remote}`
done
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文