See changes to a specific file using git

2020-02-16 05:08发布

I know that I can use the git diff command to check the changes, but, as far as I understood, 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 in one specific file? Say, I have changed files file_1.rb, file_2.rb, ..., file_N.rb, but I am only interested in the changes in the file file_2.rb. How do I check these changes then (before I commit)?

标签: git git-svn
9条回答
【Aperson】
2楼-- · 2020-02-16 06:06

You can execute

git status -s

This will show modified files name and then by copying the interested file path you can see changes using git diff

git diff <filepath + filename>
查看更多
该账号已被封号
3楼-- · 2020-02-16 06:08

Totally agree with @Greg Hewgill

And if you path includes spaces, you might use, try adding with apostrophe ' or `

git diff 'MyProject/My Folder/My Sub Folder/file_2.rb'

查看更多
三岁会撩人
4楼-- · 2020-02-16 06:11

You can use gitk [filename] to see the changes log

查看更多
登录 后发表回答