指定Git提交哈希 [英] Specifying Git commit hash

查看:75
本文介绍了指定Git提交哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以指定Git提交哈希,而不是让Git生成它吗?

Can I specify Git commit hash, instead of letting Git generate it?

有可能吗?在Git文档或在线中找不到任何方式.

Is it even possible? I didn't find any way in Git documentation or online.

对于某些背景:我正在以编程方式从私有存储库中重新创建一个新的Git公共存储库.我需要对每个提交进行很多更改以删除机密信息.但是我想保留提交ID.

推荐答案

使用git cat-file -p da500aa4f54cbf8f3eb47a1dc2c136715c9197b9可以获取的提交内容(匿名;))(用其中一个提交的sha1代替):

Content of a commit (anonymized ;) ) that you could get using git cat-file -p da500aa4f54cbf8f3eb47a1dc2c136715c9197b9 (replace with the sha1 of one of your commits):

tree 48038c4d189536a0862a2c20ed832dc34bd1c8b2
parent f0bb5942f47193d153a205dc089cbbf38299dd1a
author Firstname Lastname <my@mail.com> 1513256382 +0100
committer Firstname Lastname <my@mail.com> 1515152927 +0100

This is a commit message

如果这些数据之一发生更改,则所有sha1都会更改.

If one of these data changes, all the sha1 changes.

  • tree是根据文件和目录内容计算出的sha1.

  • The tree is the sha1 calculated from the content of the files and directories content.

Parent是父提交哈希.

请注意,里面也有日期,所以如果您执行完全相同的提交但在不同的时刻,sha1也将更改

Notice that there is also dates inside, so if you do exactly the same commit but at different moment, the sha1 will change also

PS:您可以继续使用命令git cat-file -p继续探索tree,并更好地理解git存储数据的方式.

PS: You could continue with the command git cat-file -p to continue explore the tree and better understand the way git store data.

这篇关于指定Git提交哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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