Get startedGet started for free

Version history tips and tricks

1. Version history tips and tricks

We've seen how to view the history of a repo; now, let's examine how we can customize this to suit our needs.

2. Projects grow!

Git log is great, but the longer our project goes on, the more commits we will make, and the more difficult and time-consuming it will become to find what we are looking for.

3. Restricting the number of commits

We have a few options for customizing the git log output. We can restrict the number of commits displayed by including a dash followed by the number of commits. Here, we show the three most recent commits.

4. Restricting the file

Another option is to restrict the output to a specific file. Here, we include the filename report.md, which would restrict the output to the history of this file.

5. Combining techniques

We can even combine these two techniques! Here, we change into the data directory and display our CSV file's two most recent commits!

6. git log output

We see both of these commits added more data to the file.

7. Customizing the date range

Another way to restrict the git log output is by date. Adding the dash-dash-since equals flag, followed by a date in single or double quotation marks, shows only the commits since the specified date. We use the format of month, day, and year, where month is a three-letter abbreviation, day is one or two digits, and year is four digits. For example, to see commits since the second of April 2024 we execute git log dash-dash-since equals April two, 2024. We can add an end for the date range too. Here, we show commits between the second and eleventh of April 2024 by including the dash-dash-until flag at the end, followed by the date range to filter on.

8. Acceptable filter formats

The since and until flags are very flexible in the date and time formatting that they accept. We can use natural language such as 2 weeks ago. We can also provide a date using a numeric format, like 07-15-2024. While various date formats can be used, we recommend following ISO Format 6801, providing year, month, then day, separated by hyphens. We should also check our system settings to avoid unexpected results, such as 12-06-2024 being 6th December or 12th June! We can also provide month in written format, either abbreviated or in full, such as 15 July 2024. Note that we must not use other characters here, such as commas.

9. Finding a particular commit

Suppose we have observed issues since a particular date. We need to see what changed in a specific commit on that day. We run git log and note the commit hash of interest. Generally, the first 8-10 characters of the hash are enough to be unique, so this is all we need. We can then use the git show command with the partial commit hash.

10. git show output

The output displays the log entry for that commit at the top, followed by a diff output showing changes between the file in that commit and the current version in the repo. In the following video, we'll discuss diffs and how to interpret them. At the bottom, the added line appears to have data in the wrong order, with gender in the first column instead of the second. This looks like the source of the issue!

11. Let's practice!

Time to practice customizing our logs.

Create Your Free Account

or

By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.