如何在git中获取倒数第二个提交哈希 [英] How to get second last commit hash in git

查看:107
本文介绍了如何在git中获取倒数第二个提交哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的git命令来获取最后2次提交哈希

I am using below git command to get last 2 commit hash

git log -n 2 --pretty=format:"%H"  #To get only hash value of commit

但是我只需要倒数第二次提交哈希.

But I needs only second last commit hash.

任何帮助都会很棒

谢谢

推荐答案

git rev-parse @~

rev-parse将各种符号转换为哈希,@是当前头,~是上一个提交.

rev-parse turns various notations into hashes, @ is current head, and ~ is the previous commit.

这可以概括为任意向后追溯的提交:例如,您可以编写@~3(或@~~~)来指定在当前记录头之前进行三次提交".

This generalizes to commits arbitrarily far back: for example, you can write @~3 (or @~~~) to specify "three commits before the current head".

这篇关于如何在git中获取倒数第二个提交哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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