如何获得第一次提交的Git差异? [英] How to get Git diff of the first commit?
问题描述
我创建了一个存储库,在其中创建了一个文件,在文件中放入了一些内容,然后提交了文件.现在,我想看看该提交的区别,理想情况下,它应该显示添加的文件和添加到其中的行.
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屋!