Sunday, January 29, 2017

How to use Git Client to Trace Commit History

Git is good to keep track of your code changes, especially if you do commit every time you proceed each step when you do Test-Driven Development (TDD). Moreover, you can share to others on how did you do TDD step-by-step with explanation in the commit message.


Before starting with Git, get yourself familiar with it first from this blog: Learn Git within 7 Minutes and Play Around with It. Or you can follow steps below on how you can use Git client to track code changes.

I. Git Client in Eclipse

1. Open Git perspective in Eclipse by go to menu Windows --> Perspective --> Open Perspective --> Other...


2. Select Git and click OK


3. On the left pane, you can click to Clone a Git repository or Add an existing local Git repository. In this case, I will close a Git repository from GitHub.


Or you can click the icon on the top-right corner.



4. Get the Git repository URL. In this case, I copied URL from GitHub.


5. Paste the URL in the URI field and it automatically populates other fields. Please note it is recommended to change the URL protocol from https:// to git:// in Eclipse to avoid "cannot open git-upload-pack" issue.


6. Select branch to clone. In this case, there's only one master branch to clone. Click Next.


7. Select directory you want to keep this Git repository on your local machine. Click Finish.


8. Wait until the operation is completed.


9. Now, you can see your Git repository in the left pane.



10. Right click on the repository and select Show In --> History


11. You will see the Git commit history appear on the right pane. The history is listed in anti-chronological order. You click one of them to see what files had been changed in that commit. You can double click the file to see the change.


12. You can see the file content at selected commit from the above view.

II. Git GUI

If you install Git client from https://git-scm.com/downloads then you can follow theses steps:

1. Run Git GUI and select either Clone Existing Repository or Open Existing Reposiory. In this case, I will open existing local repository.


2. Select directory of your local Git repository and click Open


3. Go to menu Repository --> Visualize master's History


4. A new window will popup with all commit history which you can choose and the change detail will be shown below.

I found this is more user-friendly to explore than it is in Eclipse. However, I cannot find an easy way to view the file at specific commit without checkout or revert. Please let me know if you know how.

III. GitHub Desktop

If you are using GitHub Desktop (downloadable from https://desktop.github.com/) then you can follow these steps:

1. Open GitGub Desktop and Click + on the top-left and choose either Add or Clone tab. In this case I choose Add to add existing local Git repository. Select your local Git directory and click Add repository.


2. On the right panel, select History tab. It will list all commit history in anti-chronological order with change of the commit showing on the right pane.

However, same as Git GUI, I cannot find a way to display the file content at specific commit without checkout/revert. Please let me know if you do know.

IV. Summary

  • If you want to just explore and trace changes in each commit, Git GUI or GitHub Desktop are more user-friendly.
  • If you want to see the full file content at specific commit then Eclipse may be a better choice. (Until I can find way to do the same in Git HUI or GitHub Desktop 😊)

Related Blog

No comments:

Post a Comment