Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 139489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:26:38+00:00 2026-05-11T07:26:38+00:00

I have a Git repository and I’d like to see how some files looked

  • 0

I have a Git repository and I’d like to see how some files looked a few months ago. I found the revision at that date; it’s 27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8. I need to see what one file looks like, and also save it as a (‘new’) file.

I managed to see the file using gitk, but it doesn’t have an option to save it. I tried with command-line tools, the closest I got was:

git-show 27cf8e84bb88e24ae4b4b3df2b77aab91a3735d8 my_file.txt 

However, this command shows a diff, and not the file contents. I know I can later use something like PAGER=cat and redirect output to a file, but I don’t know how to get to the actual file content.

Basically, I’m looking for something like svn cat.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:26:39+00:00Added an answer on May 11, 2026 at 7:26 am

    Using git show

    To complete your own answer, the syntax is indeed

    git show object git show $REV:$FILE git show somebranch:from/the/root/myfile.txt git show HEAD^^^:test/test.py 

    The command takes the usual style of revision, meaning you can use any of the following:

    1. branch name (as suggested by ash)
    2. HEAD + x number of ^ characters
    3. The SHA1 hash of a given revision
    4. The first few (maybe 5) characters of a given SHA1 hash

    Tip It’s important to remember that when using "git show", always specify a path from the root of the repository, not your current directory position.

    (Although Mike Morearty mentions that, at least with git 1.7.5.4, you can specify a relative path by putting "./" at the beginning of the path. For example:

    git show HEAD^^:./test.py 

    )

    Using git restore

    With Git 2.23+ (August 2019), you can also use git restore which replaces the confusing git checkout command

    git restore -s <SHA1>     -- afile git restore -s somebranch -- afile 

    That would restore on the working tree only the file as present in the "source" (-s) commit SHA1 or branch somebranch.
    To restore also the index:

    git restore -s <SHA1> -SW -- afile 

    (-SW: short for --staged --worktree)


    As noted in the comments by starwarswii

    It lets you pipe the contents into a file, which is great if you want to just quickly compare files from a commit.

    E.g. you can do:

    git show 1234:path/to/file.txt > new.txt  git show 1234~:path/to/file.txt > old.txt 

    then compare them.


    Using low-level git plumbing commands

    Before git1.5.x, this was done with some plumbing:

    git ls-tree <rev>
    show a list of one or more ‘blob’ objects within a commit

    git cat-file blob <file-SHA1>
    cat a file as it has been committed within a specific revision (similar to svn cat). use git ls-tree to retrieve the value of a given file-sha1

    git cat-file -p $(git-ls-tree $REV $file | cut -d " " -f 3 | cut -f 1):: 

    git-ls-tree lists the object ID for $file in revision $REV, this is cut out of the output and used as an argument to git-cat-file, which should really be called git-cat-object, and simply dumps that object to stdout.


    Note: since Git 2.11 (Q4 2016), you can apply a content filter to the git cat-file output.

    See commit 3214594, commit 7bcf341 (09 Sep 2016), commit 7bcf341 (09 Sep 2016), and commit b9e62f6, commit 16dcc29 (24 Aug 2016) by Johannes Schindelin (dscho).
    (Merged by Junio C Hamano — gitster — in commit 7889ed2, 21 Sep 2016)

    git config diff.txt.textconv "tr A-Za-z N-ZA-Mn-za-m <" git cat-file --textconv --batch 

    Note: "git cat-file --textconv" started segfaulting recently (2017), which has been corrected in Git 2.15 (Q4 2017)

    See commit cc0ea7c (21 Sep 2017) by Jeff King (peff).
    (Merged by Junio C Hamano — gitster — in commit bfbc2fc, 28 Sep 2017)


    As noted by Kira in the comments:

    If you are using LFS files, you need to run the output of show through smudge:

    git show master:blends/bigfile.blend | git lfs smudge > blends/bigfile.blend 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The best way to include JavaScript on your website is… May 11, 2026 at 12:37 pm
  • added an answer You should use the UIImagePickerController to retrieve images from the… May 11, 2026 at 12:37 pm
  • added an answer Upgrade to MySQL 5.1. It supports ExtractValue(xml_frag, xpath_expr) May 11, 2026 at 12:37 pm

Related Questions

Say I have a git repository and I've been working on master, can I
I am new to git, and have a subversion repository that I want to
I have a git repository with remote foo. foo is a web app, is
I have a git repository which tracks an svn repository. I cloned it using
I have a git repository with multiple branches. How can I know which branches
I have a Git repository and I'd like to see how some files looked
I have a remote Git repository, and I need to roll back the last
I have a repository on github with a main branch (master) and a branch

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.