简体   繁体   English

如何查看文件上的git diff?

[英]How to view the git diff on a file?

I cloned a git project into a folder on my desktop. 我将git项目克隆到了桌面上的文件夹中。 I want to see the changes made on a certain file throughout its lifetime. 我想查看特定文件在整个生命周期中所做的更改。 I tried the 我尝试了

git log -- <filename>

command, yet this did not produce any output. 命令,但是没有产生任何输出。 I'm guessing that cloning a project does not necessarily clone the history as well? 我猜克隆项目不一定也可以克隆历史吗? I can go on github and somewhat view the changes made to a file in a certain revision (yet this is polluted with the changes made in other files also). 我可以继续在github上查看某些版本中对文件所做的更改(但是这也会被其他文件中的更改所污染)。 If anyone can give me point me in a general direction that would be great. 如果有人可以给我指出一个总体方向,那将是很好的。

Cloning a repository copies the entire history all the way back to the first commit. 克隆存储库会将整个历史记录一直复制到第一次提交。

One way to get there at the risk of overwhelming yourself with lots of detail from various contexts is 一种到达那里的风险是,您会从各种背景中获取大量细节,从而使自己不知所措

git log --all -- filename

To see the changes (or patches or deltas) made with each commit, run 要查看每次提交所做的更改(或补丁或增量),请运行

git log --all --patch -- filename

When viewing patches, I generally do not want to see clutter from whitespace-only changes, so I run 查看补丁程序时,我通常不希望看到仅空格更改带来的混乱,因此我运行

git log --all --patch --ignore-all-space -- filename

To save a bit of typing, the above command is equivalent to 为了节省键入时间,上述命令等效于

git log --all -p -w -- filename

Because of --all , this may show much more than you care about and will leave you to puzzle out which changes belong to which branch. 由于--all ,这可能显示的内容远远超出您的关心,并且会让您困惑哪些更改属于哪个分支。 To narrow it down, you can look at changes on a particular branch with 要缩小范围,您可以查看特定分支上的更改

git log -p -w my-branch -- filename

or possibly a commit range as in 或可能的提交范围

git log -p -w origin/master..master -- filename

You do not necessarily have to switch branches because git log has access to the entire repository. 您不必切换分支,因为git log可以访问整个存储库。

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

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