DEV Community

Viktor Le
Viktor Le

Posted on

4 1 1

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

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

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.

Sentry image

Make it make sense

Only get the information you need to fix your code that’s broken with Sentry.

Start debugging →

👋 Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay