git diff between two different files

痴心易碎 提交于 2020-02-16 13:28:03

问题


In HEAD (the latest commit), I have a file named foo. In my current working tree, I renamed it to bar, and also edited it.

I want to git diff foo in HEAD, and bar in my current working tree.


回答1:


Check out the --find-renames option on git-diff at https://www.kernel.org/pub/software/scm/git/docs/git-diff.html

Or specify the paths explicitly:

git diff HEAD:full/path/to/foo full/path/to/bar

(Credit goes to twaggs from Git: How to diff two different files in different branches?)




回答2:


I believe using --no-index is what you're looking for:

git diff [<options>] --no-index [--] <path> <path>

as mentioned in the git manual:

This form is to compare the given two paths on the filesystem. You can omit the --no-index option when running the command in a working tree controlled by Git and at least one of the paths points outside the working tree, or when running the command outside a working tree controlled by Git.




回答3:


If you are using tortoise git you can right-click on a file and git a diff by: Right-clicking on the first file and through the tortoisegit submenu select "Diff later" Then on the second file you can also right-click on this, go to the tortoisegit submenu and then select "Diff with yourfilenamehere.txt"




回答4:


Using PhpStorm, I just copy prev commit code and compare it with current version using built in "compare with clipboard" tool.



来源:https://stackoverflow.com/questions/16683121/git-diff-between-two-different-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!