Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

See changes to a specific file using git

Tags:

git

git-svn

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)?

like image 418
Mellon Avatar asked Nov 08 '11 09:11

Mellon


People also ask

How do I see commits in a specific file?

On Linux you can use gitk for this. It can be installed using "sudo apt-get install git-gui gitk". It can be used to see commits of a specific file by "gitk <Filename>".

How do I see commits to a specific file in github?

By navigating directly to the commits page of a repository. By clicking on a file, then selecting History, to get to the commit history for a specific file.

How do I see changes in a specific commit?

Looking up changes for a specific commit If you have the hash for a commit, you can use the git show command to display the changes for that single commit. The output is identical to each individual commit when using git log -p .


2 Answers

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).

like image 118
Greg Hewgill Avatar answered Oct 28 '22 23:10

Greg Hewgill


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.

like image 32
AJ Zane Avatar answered Oct 29 '22 00:10

AJ Zane