See changes to a specific file using git
I know in git, I can use the git diff
command to check the changes, but (what I understood is that) it is directory based. This means it gives all the changes of all files on the current directory.
How can I check only the changes on one specific file? Say, I have changed file_1.rb, file_2.rb, ..., file_N.rb, but I am only interested in the changes on file file_2.rb. How to check then?
I'd like to check the changes before I commit it.
Use a command like:
git diff file_2.rb
See the git diff
documentation for full information on the kinds of things you can get differences for.
Normally, git diff
by itself shows all the changes in the whole repository (not just the current directory).
您可以使用gitk [filename]
查看更改日志
Another method (mentioned in this SO answer) will keep the history in the terminal and give you a very deep track record of the file itself:
git log --follow -p -- file
This will show the entire history of the file (including history beyond renames and with diffs for each change).
In other words, if the file named bar was once named foo, then git log -p bar (without the --follow option) will only show the file's history up to the point where it was renamed -- it won't show the file's history when it was known as foo. Using git log --follow -p bar will show the file's entire history, including any changes to the file when it was known as foo.
链接地址: http://www.djcxy.com/p/22660.html上一篇: git diff文件反对它的最后更改
下一篇: 使用git查看对特定文件的更改