Repository Investigation — Git log & Rails

Christopher
Coding Tidbits
Published in
4 min readAug 28, 2018

How to use git log to solve version issues

Why is this important?

On larger solo or group projects, your repo will go through many iterations of changes, and it becomes increasingly difficult to know which changes could have unknown impacts on existing code. In my case, I made one change to one .erb file as part of a larger git repo commit. Eight commits later and expecting all facets of the application to work coherently, I realized that one form in particular no longer worked as it had previously. This post will recreate my troubleshooting steps in pinpointing exactly when and how I broke my functioning code.

Git Log Troubleshooting Steps

Step 1: Populate list of commits to the project folder.

git log shows all commits to the repo in reverse chronological order, most recent commits toward the top.

git log --oneline shows all commits on a single line to make data viewing more succinct and more easily navigable.

Step 2: I know that my “comments” form on my picture show page worked recently, but does not work any longer; so, I limit my search to the 15 most recent commits. Scan through the most recent commits to determine where the change to the file in question may have occurred. I see that a change was made on line 9 to the “comments controller and views and pic form”; therefore, this is where I will start my search. The yellow text at the beginning of the line is the commit number.

git log --pretty=oneline -15 shows the most recent commits.

Step 3: I use the commit number to call the specific commit via the terminal. This will show changes between this commit and its previous version.

git show <commit number>shows all changes made in that commit

Step 4: After scanning through all the changes made in the commit I ‘showed’, I notice that this is where I created the comments form and NOT when I edited the form. So I know that one of the more recent commits must be the source of my error.

Step 5: I used git checkout <commit number> to checkout a new branch and pull in that commit’s code. I fired up the server using rails s to test the form in question, and found that it indeed worked. I returned to my original branch after confirming the code’s functionality.

Step 6: After returning to my original branch, I used log once again to quickly scan over a couple more versions to find a place where I made a change to this form.

Backstory: I made this change (removed the ‘=’) forgetting that this is required in forms even if you do not intend on printing it to the browser screen, unlike when working with non-form .erb files. My original intention was to execute the code and hide it from the show.

Step 7: I fixed my broken code by reinstating the form ‘=’ and hiding the form boxes from the display using style= “display: none” within the opening div for these form items.

Most important take-aways from this specific experience:

  • Commit routinely!
  • Be specific in commits comments.
  • Use the terminal to pinpoint rough location of changes.

--

--