如何获得第一次提交的Git差异? [英] How to get Git diff of the first commit?

查看:65
本文介绍了如何获得第一次提交的Git差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个存储库,在其中创建了一个文件,在文件中放入了一些内容,然后提交了文件.现在,我想看看该提交的区别,理想情况下,它应该显示添加的文件和添加到其中的行.

I created a repo, created a file inside it, put some content in the file, and committed the file. Now, I'd like to see a diff of that commit, which should ideally show the file that was added and the lines that were added to it.

但是,git diff HEAD^ HEAD返回fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree.,可能是因为这是对存储库的第一次提交.

However, git diff HEAD^ HEAD returns fatal: ambiguous argument 'HEAD^': unknown revision or path not in the working tree., probably because this was the first commit to the repo.

如何解决?仍然有办法查看第一次提交中添加的文件的差异吗?

How can this be resolved? Is there still a way to view a diff of the files that were added in the first commit?

推荐答案

您可以这样做:

git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 HEAD

4b825dc642cb6eb9a060e54bf8d69288fbee4904是Git中空树"的ID,并且在每个存储库中始终可用.

4b825dc642cb6eb9a060e54bf8d69288fbee4904 is the id of the "empty tree" in Git and it's always available in every repository.

这篇关于如何获得第一次提交的Git差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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