DEV Community

Cover image for Using Git to see recent changes in specified a time period
Johnny Simpson
Johnny Simpson

Posted on • Edited on • Originally published at fjolt.com

Using Git to see recent changes in specified a time period

Have you ever gone on a long holiday and wanted to check the updates your team have made since 2 weeks ago? Or maybe even in just the last week. Sure, you could trawl through PRs, but there may be an easier solution. Git has built in functionality to check just this.

If you want to view the last 2 weeks of changes, you can use git log. For example, to view the last two weeks of changes your repository, run the following in terminal:

git log --since='2 weeks ago'
Enter fullscreen mode Exit fullscreen mode

Similarly, if you only wanted to view one week of changes, you'd write:

git log --since='2 weeks ago'
Enter fullscreen mode Exit fullscreen mode

The date for the --since variable can be given like 2 weeks ago, 1 year ago, 2 months ago, or 5 days ago - so you have a lot of flexibility as to how you want to show the changes. You can also use ISO timestamps, such as 2022-03-03T14:32:12-01:00

Note: you can also use git whatchanged, which does exactly the same thing as git log, but is kept around for historical reasons. The only difference between git whatchanged and git log is that git whatchanged shows all files in a change by default.

It is recommended to use git log instead, as it's still possible to show all files using this command too, by typing git log --since='2 weeks ago' --stat

Other git log options

As well as being able to give you a simple interface to view changes, there are some useful features git log has which can add more information to the log you receive. Here are some of my favourites:

  • --max-count or -n - limits the maximum count of git commits - can be used like git log --since='2 weeks ago' --max-count=5
  • --author or --committer - shows commits by a specific author, i.e. git log --since='2 weeks ago' --author="joe"
  • --merges or --no-merges - either shows only merges, or hides all merges.
  • --grep - limits the log by log item, so git log --since='2 weeks ago' --grep="feat-ui"will only show changes with 'feat-ui'.
  • --stat - lists all the files made in a particular change.
  • -p - which shows file by file changes.

Top comments (0)