Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过短哈希获得GIT提交消息的更好方法?_Git_Bash_Awk_Grep_Git Log - Fatal编程技术网

通过短哈希获得GIT提交消息的更好方法?

通过短哈希获得GIT提交消息的更好方法?,git,bash,awk,grep,git-log,Git,Bash,Awk,Grep,Git Log,我当前正在使用以下命令获取某个提交哈希的提交消息: hash='b55da97' git log --pretty=oneline ${hash} | grep "${hash}" | awk '{ print $2 }' 不过,这些措施似乎效率极低。有没有更聪明或更便宜的方法来做这件事,或者我是不是被困在greping和awking中了?这可能会缩短一些时间 git log --pretty=oneline ${hash} | awk '$0~var {print $2}' var="${h

我当前正在使用以下命令获取某个提交哈希的提交消息:

hash='b55da97'
git log --pretty=oneline ${hash} | grep "${hash}" | awk '{ print $2 }'
不过,这些措施似乎效率极低。有没有更聪明或更便宜的方法来做这件事,或者我是不是被困在greping和awking中了?

这可能会缩短一些时间

git log --pretty=oneline ${hash} | awk '$0~var {print $2}' var="${hash}"

根据您实际需要的提交消息的数量,您可以使用几个漂亮的格式说明符:

      ·  %s: subject
      ·  %f: sanitized subject line, suitable for a filename
      ·  %b: body
      ·  %B: raw body (unwrapped subject and body)

所以类似于
git log-1--pretty=format:%b
,或者使用其他一个说明符(我认为
%s
可能更接近您现在正在做的事情)。
-1
git日志
限制为仅提交一次,而不是遍历历史树。

git日志
包括以下内容:

  • -n num
    要限制显示的提交数量,请选择1(如果
    num
    为9或更少,您可以只写
    -num
    ,因此,简称
    -1
  • --pretty=format:带有指令的字符串,用于更改日志输出格式。
    %s
    指令获取commit“subject”,这也是使用
    oneline
    获得的
因此:
git log-n1--pretty=format:%s$hash
(或者
git log-1--pretty=format:%s
)将在这里实现这个技巧


有关格式指令的完整列表,请参阅“漂亮格式”下的。

我喜欢将重要内容转储到一行中。。。以下是我在本页其他答案的基础上使用的内容:

git_log_for_commit.sh 输出
一个比这里列出的更简短的答案是


git log--pretty=oneline{your_hash}grep{your_hash}

您已经非常接近了,只需将输出限制为1 commit,并使用不同的--pretty:
git log-n1--pretty=格式:%s$hash
@torek加上一个到您的评论中,如果您想将此作为答案,则+1并接受。很好,先生,再加一个给您
IT=$(git log -1 --pretty=format:"%an, %s, %b, %ai"  $*)
echo "$IT"
jdoe, WORK1766032 - Added templating engine, WIP, 2013-08-15 14:25:59 +0000