简体   繁体   English

我可以对名称已更改的文件进行git diff吗?

[英]Can I git diff a file which name has changed?

When a file name or path changes, git status doesn't tell me that there is a modified file, it tells me that there is a deleted file and a created file. 当文件名或路径更改时, git status不会告诉我存在已修改的文件,而是会告诉我存在已删除的文件和已创建的文件。 git diff shows me all the content of the previous version of the file, and doesn't show me the new content (since it's a new file). git diff向我显示了文件先前版本的所有内容,而没有向我显示新内容(因为它是一个新文件)。

Is it possible to see the changes in a file which name or path has changed? 是否可以查看文件中名称或路径已更改的更改?

Yes, add both the deleted and created file and then run a diff on the index: 是的,添加已删除和创建的文件,然后在索引上运行差异:

git add oldname newname
git diff --cached oldname newname

If the files are too different, the diff will show them separately, otherwise will show them as a single file updated (with a new name, and some updated content). 如果文件太不同,差异将分别显示它们,否则将显示为已更新的单个文件(具有新名称和一些更新内容)。

Also, as @YesThatIsMyName mentioned, you can do the file renaming in Git directly using git mv oldname newname to not have to run git add oldname newname after having moved them. 另外,正如@YesThatIsMyName所述,您可以在git mv oldname newname直接使用git mv oldname newname重命名文件,而不必在移动它们后运行git add oldname newname

You can use --follow switch with git log . 您可以将--follow开关与git log一起使用 It will show a history of the changes committed, even after renames. 即使重命名,它也会显示已提交更改的历史记录。

git log --follow renamedfile.cs

For more info, see here . 有关更多信息,请参见此处

Also, see this interesting related question here . 另外,请在此处查看这个有趣的相关问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM