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

Heroku

Deploy with ease. Manage efficiently. Scale faster.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

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.

Image of DataStax

AI Agents Made Easy with Langflow

Connect models, vector stores, memory and other AI building blocks with the click of a button to build and deploy AI-powered agents.

Get started for free

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay