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

  • SEARCH
  • Home
  • 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 246941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:12:51+00:00 2026-05-11T21:12:51+00:00

I have the file main.cpp open in my editor. I want to see the

  • 0

I have the file “main.cpp” open in my editor.

I want to see the previous revision of “main.cpp” in the editor too.

The way I do it now is like this.

close "main.cpp" in the editor

prompt> mv main.cpp tmp
prompt> git checkout HEAD^ main.cpp
prompt> mv main.cpp old_main.cpp
prompt> mv tmp main.cpp
prompt>

open "main.cpp" and "old_main.cpp" in the editor

Can it be simplified, so I don’t have to close “main.cpp” in the editor?

What I’m hoping for is a variant of git-checkout that can do this.


UPDATE: im using git on mac osx 10.5.7

prompt> git --version
git version 1.6.0.4
prompt> 

UPDATE2: Jakub Narębski answer is:

prompt> git show HEAD^:dir1/dir2/dir3/main.cpp > old_main.cpp
prompt>

UPDATE3: Karmi’s answer, for a specific revision:

prompt> git show 4c274dd91dc:higgs/Higgs.xcodeproj/project.pbxproj > old_project.pbxproj
prompt> 
  • 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. Editorial Team
    Editorial Team
    2026-05-11T21:12:52+00:00Added an answer on May 11, 2026 at 9:12 pm

    You can use git show for that:

    git show HEAD^:main.cpp > old_main.cpp
    

    (Note that there is colon [:] character between HEAD^ and main.cpp.) The <revision>:<path> syntax is described in git rev-parse manpage, next to last point in the "Specifying revisions" section:

    <rev>:<path>, e.g. HEAD:README, :README, master:./README

    A suffix : followed by a path names the blob or tree at the given path in the tree-ish
    object named by the part before the colon. :path (with an empty part before the colon)
    is a special case of the syntax described next: content recorded in the index at the
    given path. A path starting with ./ or ../ is relative to the current working directory.
    The given path will be converted to be relative to the working tree’s root directory.
    This is most useful to address a blob or tree from a commit or tree that has the same
    tree structure as the working tree.

    Note that <path> here is FULL path relative to the top directory of your project, i.e. the directory with .git/ directory. (Or, to be more exact, to "<revision>", which in general can be any <tree-ish>, i.e. something that represents tree.)

    If you want to use path relative to the current directory, you need to use ./<path> syntax (or ../path to go up from current directory).

    Edit 2015-01-15: added information about relative path syntax


    You can get in most cases the same output using low-level (plumbing) git cat-file command:

    git cat-file blob HEAD^:main.cpp > old_main.cpp
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code that looks like this: int main () { fstream file;
I have many source/text file, say file.cpp or file.txt . Now, I want to
I have three files, a main .cpp file: #include <stdio.h> #include myClass.h int main()
Can't understand what is a problem here: I have got main.cpp file where I
I have a javascript file main.js and five html files 1.html,2.html,3.html,4.html,5.html I want to
I have a file named main.cpp which includes iostream . I compiled main.cpp and
I currently have a program where my main code is in a file main.cpp.
I am in linux. My Makefile file is this main2: main.cpp g++ -c $(LIBS)
I am creating a program to copy a text file. I have a main.cpp
I have a xml file main.xml with following markup and data. main.xml <xml> <content>

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.