Sentry Answers>Git>

View the change history of a single file in Git

View the change history of a single file in Git

David Y.

The Problem

How can I see the change history of a single file in my Git repository?

The Solution

We can show the full change history of a file, taking renames into account, using the git log command:

Click to Copy
git log --follow --patch -- name-of-file

The --patch/-p flag generates patch text, i.e. diffs of the file across commits. The --follow flag will include changes across renames in our change log. Note that --follow will only work if we’re looking at a single file – we should remove this flag if we’re viewing the history of multiple files, or want to exclude history past the file’s most recent renaming.

The above git log command will output our file’s history as a series of diffs. Alternatively, we can view this information in gitk, Git’s built-in repository visualizer, by entering this command:

Click to Copy
gitk name-of-file
  • Syntax.fmListen to the Syntax Podcast
  • ResourcesWhat is Distributed Tracing
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski.

    SEE EPISODES

Considered “not bad” by 4 million developers and more than 100,000 organizations worldwide, Sentry provides code-level observability to many of the world’s best-known companies like Disney, Peloton, Cloudflare, Eventbrite, Slack, Supercell, and Rockstar Games. Each month we process billions of exceptions from the most popular products on the internet.

© 2024 • Sentry is a registered Trademark
of Functional Software, Inc.