本文介绍了命令从分支中获取最新的git提交散列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用命令行检查特定git分支的最新提交散列? 使用<$ c 使用 git ls-remote git://github.com/< user> /< project> .git 。例如,我的trac-backlog项目给出了:

$ p $ g $ ls-remote git: TRAC-backlog.git
5d6a3c973c254378738bdbc85d72f14aefa316a0 HEAD
4652257768acef90b9af560295b02d0ac6e7702c参/头/ 0.1.x
35af07bc99c7527b84e11a8632bfb396823326f3参/头/ 0.2.X
5d6a3c973c254378738bdbc85d72f14aefa316a0参/头/主
520dcebff52506682d6822ade0188d4622eb41d1裁判/拉/ 11 /头
6b2c1ed650a7ff693ecd8ab1cb5c124ba32866a2裁判/拉/ 11 /合并
51088b60d66b68a565080eb56dbbc5f8c97c1400裁判/拉/ 12 /头
127c468826c0c77e26a5da4d40ae3a61e00c0726裁判/拉/ 12 /合并
2401b5537224fe4176f2a134ee93005a6263cf24裁判/拉/ 15 /头
8aa9aedc0e3a0d43ddfeaf0b971d0ae3a23d57b3裁判/拉/ 15 /合并
d96aed93c94f97d328fc57588e61a7ec52a05c69裁判/拉/ 7 /头
f7c1e8dabdbeca9f9060de24da4560abc76e77cd裁判/拉/ 7 /合并
aa8a935f084a6e1c66aa939b47b9a5567c4e25f5裁判/拉/ 8 /头
cd2 58b82cc499d84165ea8d7a23faa46f0f2f125裁判/拉/ 8 /合并
c10a73a8b0c1809fcb3a1f49bdc1a6487927483d裁判/标签/ 0.1.0
a39dad9a1268f7df256ba78f1166308563544af1裁判/标签/ 0.2.0
2d559cf785816afd69c3cb768413c4f6ca574708裁判/标签/ 0.2.1
434170523d5f8aad05dc5cf86c2a326908cf3f57裁判/tags/0.2.2
d2dfe40cb78ddc66e6865dcd2e76d6bc2291d44c refs / tags / 0.3.0
9db35263a15dcdfbc19ed0a1f7a9e29a40507070 refs / tags / 0.3.0 ^ {}

只需grep就可以找到你需要的东西并剪下来:

  :: git ls-remote git://github.com/jszakmeister/trac-backlog.git | \ 
grep refs / heads / master | cut -f 1
5d6a3c973c254378738bdbc85d72f14aefa316a0

或者,您可以在命令中指定想要的参数并避免grep:

  :: git ls-remote git://github.com/jszakmeister/trac-backlog .git refs / heads / master | \ 
cut -f 1
5d6a3c973c254378738bdbc85d72f14aefa316a0

注意:它没有必须是 git:// url,它可以是 https:// [email protected]

How can I check with the command line the latest commit hash of a particular git branch?

解决方案

Use git ls-remote git://github.com/<user>/<project>.git. For example, my trac-backlog project gives:

:: git ls-remote git://github.com/jszakmeister/trac-backlog.git
5d6a3c973c254378738bdbc85d72f14aefa316a0    HEAD
4652257768acef90b9af560295b02d0ac6e7702c    refs/heads/0.1.x
35af07bc99c7527b84e11a8632bfb396823326f3    refs/heads/0.2.x
5d6a3c973c254378738bdbc85d72f14aefa316a0    refs/heads/master
520dcebff52506682d6822ade0188d4622eb41d1    refs/pull/11/head
6b2c1ed650a7ff693ecd8ab1cb5c124ba32866a2    refs/pull/11/merge
51088b60d66b68a565080eb56dbbc5f8c97c1400    refs/pull/12/head
127c468826c0c77e26a5da4d40ae3a61e00c0726    refs/pull/12/merge
2401b5537224fe4176f2a134ee93005a6263cf24    refs/pull/15/head
8aa9aedc0e3a0d43ddfeaf0b971d0ae3a23d57b3    refs/pull/15/merge
d96aed93c94f97d328fc57588e61a7ec52a05c69    refs/pull/7/head
f7c1e8dabdbeca9f9060de24da4560abc76e77cd    refs/pull/7/merge
aa8a935f084a6e1c66aa939b47b9a5567c4e25f5    refs/pull/8/head
cd258b82cc499d84165ea8d7a23faa46f0f2f125    refs/pull/8/merge
c10a73a8b0c1809fcb3a1f49bdc1a6487927483d    refs/tags/0.1.0
a39dad9a1268f7df256ba78f1166308563544af1    refs/tags/0.2.0
2d559cf785816afd69c3cb768413c4f6ca574708    refs/tags/0.2.1
434170523d5f8aad05dc5cf86c2a326908cf3f57    refs/tags/0.2.2
d2dfe40cb78ddc66e6865dcd2e76d6bc2291d44c    refs/tags/0.3.0
9db35263a15dcdfbc19ed0a1f7a9e29a40507070    refs/tags/0.3.0^{}

Just grep for the one you need and cut it out:

:: git ls-remote git://github.com/jszakmeister/trac-backlog.git | \
   grep refs/heads/master | cut -f 1
5d6a3c973c254378738bdbc85d72f14aefa316a0

Or, you can specify which refs you want on the command line and avoid the grep with:

:: git ls-remote git://github.com/jszakmeister/trac-backlog.git refs/heads/master | \
   cut -f 1
5d6a3c973c254378738bdbc85d72f14aefa316a0

Note: it doesn't have to be the git:// url, it could be https:// or [email protected]: too.

这篇关于命令从分支中获取最新的git提交散列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 08:29