从提交消息git获取提交ID [英] get commit id from commit message git

查看:215
本文介绍了从提交消息git获取提交ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个月前解决了一个bug,但似乎仍然存在一些问题。
但我甚至不记得我迄今为止所做的修改。那时我已经注意到bug名称
了。所以要找到它的提交ID,只有一种方法可以通过 git log 和搜索 commit 消息。
我试过这种方式:

  git log --author = githubUser | grep65243

但它只是给我回复消息:

  merge UI Developers Work#65243 

有没有办法通过执行 grep 来获取它的提交ID。



git中的消息日志将采用以下格式:

  commit< commit_id> 
作者:githubUser< githubUser@companyname.com>
日期:Thu Jul X 15:55:23 2014 +0530

Bug修复#65243

$ b $ 第一个和最短的是使用 gitrevisions 语法来指定第一个修订版在其提交消息中包含给定的字符串:

  git rev-parse:/ 65243 



和:

  git show:/ 65243 

引用上面链接的文档:


冒号后跟一个斜杠,后跟一个文本,命名提交消息与指定正则表达式匹配的提交。该名称返回可从任何ref访问的最年轻匹配提交。如果提交消息以!开头你必须重复这一点;特殊序列:/!,后面是除!之外的其他内容,现在保留。正则表达式可以匹配提交消息的任何部分。为了匹配以字符串开头的消息,可以使用例如:/ ^ foo中。

这种表达形式命名特定的提交(即,它具有与原始SHA-1 ID相同的用法),即为什么 git rev-parse 会显示修订ID和 git show 会显示提交本身。






如果选择了错误的版本,请使用 git log --grep = 65243 将其输出限制为那些提交消息中包含指定正则表达式的提交。不同之处在于,这看起来与 git log 会以其他方式显示的相同修订相同(因此您可以添加其他限制器),并显示所有匹配的修订。也就是说,你可以这样做:

  git log --since = ... --before = ...  - -author = ... --grep = 65243 branch〜30..branch 

查看提交可以从分支但不能从分支〜30 到达,发生在两个时间戳之间,具有给定的作者,以及包含 65243 。 (将 - oneline - format = pretty:... 字符串添加到 git log 命令,如果需要的话,等等。)


I had resolved a bug one month before, but still seems to be there are some issues with it. But I don't even remember what changes I had done so far to fix that. I had noted the bug name that time. So to find its commit Id there is only one way that go through the git log and search in commit messages. I tried this way :

      git log  --author=githubUser | grep "65243" 

But its just returning me the message like :

     merge UI Developers Work #65243

Is there any way to get its commit id by doing grep in to it.

The message in the git log would be in the following format:

    commit <commit_id>
    Author: githubUser <githubUser@companyname.com>
    Date:   Thu Jul X 15:55:23 2014 +0530

        Bug fixed #65243

解决方案

There are two methods to do what you want, depending on exactly what you want.

The first and shortest is to use gitrevisions syntax to specify the "first" revision that contains a given string in its commit message:

git rev-parse :/65243

and:

git show :/65243

Quoting from the documentation linked above:

A colon, followed by a slash, followed by a text, names a commit whose commit message matches the specified regular expression. This name returns the youngest matching commit which is reachable from any ref. If the commit message starts with a ! you have to repeat that; the special sequence :/!, followed by something else than !, is reserved for now. The regular expression can match any part of the commit message. To match messages starting with a string, one can use e.g. :/^foo.

This form of expression names a specific commit (i.e., it has the same usage as a raw SHA-1 ID), which is why git rev-parse will show you the revision-ID and git show will show you the commit itself.


If that picks the wrong revision, use git log --grep=65243 to limit its output to those commits that contain the specified regular expression in their commit messages. The difference is that this looks only at the same revisions that git log would show otherwise (so you may add additional limiters), and shows all matching revisions. That is, you can do things like:

git log --since=... --before=... --author=... --grep=65243 branch~30..branch

to see commits that are reachable from branch but not from branch~30, happened between the two time stamps, have the given author, and contain 65243. (Add --oneline or a --format=pretty:... string to the git log command if desired, etc.)

这篇关于从提交消息git获取提交ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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