How can I see the change history of a single file in my Git repository?
We can show the full change history of a file, taking renames into account, using the git log
command:
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:
gitk name-of-file
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.