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:
- Git command will list all commits for a file:
git log --oneline --follow -- the-path-to-the-file
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
It's a handy little command for those times where you want to see all the Git commit ids associated with a file.
- 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
Top comments (2)
Interesting! This is a good approach to understanding unintentional changes, especially when tracking down unexpected fixes. Thanks for sharing these Git commands.
That's right.