Skip to main content

Git Tip of the Day -- What Changed?

Development
git
/development
/version-control
2 min read

Discovering Changes in Your Git Repository

So you've just come back from vacation and want to see what your co-workers have been up to? Or maybe you're returning to a project after a long break and need to catch up. Git has a powerful, yet often overlooked, command that can show you all the commits that have happened since you last checked in.

The Command: git whatchanged

The git whatchanged command is a great way to review the history of changes in your repository. Here’s how you can use it:

git whatchanged --since='2019-04-11'

This command will display all the commits made since April 11, 2019. Replace the date with the one relevant to your needs.

Use Friendly Dates

Git also supports relative dates, making it easier to specify timeframes without looking up exact dates. For example:

git whatchanged --since='yesterday'
git whatchanged --since='3 weeks ago'

These commands will show you commits made since "yesterday" or "3 weeks ago," respectively.

Why Use git whatchanged?

While git log is the more commonly used command for viewing commit history, git whatchanged provides a more detailed view of changes, including file-level modifications. It’s particularly useful for:

  • Code Reviews: Quickly reviewing what’s been added, modified, or removed.
  • Debugging: Identifying changes that might have introduced bugs.
  • Team Collaboration: Understanding what your team has been working on while you were away.

Pro Tips

  1. Filter by Author: If you want to see changes made by a specific team member, you can combine --since with --author:

    git whatchanged --since='1 week ago' --author='John Doe'
  2. Limit the Output: To avoid being overwhelmed by too much information, use the -n flag to limit the number of commits displayed:

    git whatchanged -n 5 --since='1 month ago'
  3. Combine with File Filters: Focus on changes to specific files or directories:

    git whatchanged --since='2 weeks ago' -- path/to/file

A Note on Deprecation

It’s worth mentioning that git whatchanged is considered somewhat deprecated in favor of git log. Most of its functionality can be replicated with git log using the --stat or --name-status options. For example:

git log --since='2 weeks ago' --stat

However, if you’re already comfortable with git whatchanged, it remains a useful tool for exploring commit history.

Final Thoughts

Whether you’re catching up after a break or diving into a new project, understanding what’s changed in your repository is crucial. Commands like git whatchanged and its alternatives can help you stay informed and productive.