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 ProblemJump To Solution

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
  • ResourcesWhat is Distributed Tracing
  • Syntax.fm logo
    Listen to the Syntax Podcast

    Tasty Treats for Web Developers brought to you by Sentry. Web development tips and tricks hosted by Wes Bos and Scott Tolinski

    Listen to Syntax

Loved by over 4 million developers and more than 90,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.