DEV Community

Viktor Le
Viktor Le

Posted on

How to review all git changes in a file

Have you ever come into a situation that a production issue happened in the last two months but it was automatically fixed after that? Then, you brainstorm that it might a good side-effect change in a file which fixed that issue inadvertently.

To investigate the issue with a hard-work you need a tool like viewing all changes in the last two months. And in this post, I will show you two handy tools:

  1. Git command will list all commits for a file:
git log --oneline --follow -- the-path-to-the-file
Enter fullscreen mode Exit fullscreen mode

For example, you have a file, named: foo.js in a src/app folder. The command you should type is:

git log --oneline --follow -- src/app/foo.js
Enter fullscreen mode Exit fullscreen mode

It's a handy little command for those times where you want to see all the Git commit ids associated with a file.

  1. Gitk command

A website needs a browser, and a file also needs Gitk to view too. You can read more in git docs

In Mac, if you do not still have it, then run brew install git-gui to install it. You can read this StackOverflow post in case you have trouble during the installation.

So, to view the changes in a foo.js visually, just run the below command:

gitk src/app/foo.js
Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
programmerraja profile image
Boopathi

Interesting! This is a good approach to understanding unintentional changes, especially when tracking down unexpected fixes. Thanks for sharing these Git commands.

Collapse
 
viktorle1294 profile image
Viktor Le

That's right.