Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

retrieve files from a specific commit

Valgardur Gudjonsson October 13, 2016

Can I retrieve / download files from a specific commit?

I don't want to set the commit in question as current version.

If I select all the files I want, the only option on right-click is "Open Current Version".

If I select one file - which would be a pain - I have "Open Selected Version" on right-click - but nothing happens.

2 answers

2 votes
d10 September 20, 2018

There is a clean and easy way to do this in Sourcetree without checking out:

  1. Select the commit
  2. Select one or more files in the commit, right-click them, and select "Log Selected". This opens a new window.
  3. Right-click the selected commit and select "Reset Files to This Commit".

Done!

0 votes
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 13, 2016

Why would you deny to checkout the commit as current version?

That's one of the main purposes of a VCS: Switch the version simply and fast ....

Just as a recipe for simple getting the desired version of your files:

  • Put all the currently uncommited changes of your current version to the stash via git stash....
  • Checkout the desired version
  • Copy the desired files to a save palce
  • Checkout the HEAD again
  • Re-apply your stash
  • .... and you are done ...
Valgardur Gudjonsson October 13, 2016

Thanks for (an extremely) quick reply..

Perhaps I am misunderstanding, but this particular version is not the current version, and would not work, and if any other user would "pull" he would get an obsolete version.

I am tracing changes for some historic documentation - so I don't want to see this in the history or trouble other users.

Just moved to Git from SubVersion, there I could, using Tortoise, easily select a specific commit and download.. is this really not possible?

Using SourceTree, not command line..

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 16, 2016

I don't understand your question ...

 

Maybe you have not fully understood the concepts of a distributed VCS or you choose a wrong/misleading wording: @Valgardur Gudjonsson wrote: "easily select a specific commit and download.".  

  • I don't get it here: with git you pull an ENTIRE repository (including its complete history) from a remote machine (that's what I personally would consider as "download" - unless I would prefer the exact term "pull"). After pulling you have the complete repository on your local machine: most of the actions you perform, work with your LOCAL repository.
  • git does not work with single files - but rather with "snapshots": a snapshot represents the state of ALL files within the repository at a certain point of time. Checking in a file creates a new commit and therefore a new snapshot - representing the state of ALL the files at this moment. Unless you might have committed a single file, the commit nevertheless describes the state of all files at this moment. Checking out a commit "reconstructs" the snapshot at the time of the commit.

So the way to go is:

  •  Pull a remote repository ("Download" a remote repository to your local machine including the COMPLETE history of the entire repository)
  •  Check out a desired Commit (i.e. retrieves a "snapshot", reconstructing the source code situation at the time of the commit)


So you don't "download a commit of a single file": 1.) pull gets ("downloads") the complete repository, 2.) checking out a commit reconstructs the file constellation/versions of all files at the time of the commit.

I tried to describe the following in my answer:

  • Checkout the desired version - that means: Checkout the commit, which contains your file in your desired version
  • Having this, you have your desired file in your sandbox -> Copy the desired files to a safe place
  • Checkout the HEAD again - that means: Checkout the most recent commit, i.e the latest version. Your desired file is still available at your safe place...
Valgardur Gudjonsson October 17, 2016

Thanks for a detailed reply, but I guess I did not explain my problem well enough or perhaps I used misleading words..

I do understand how git works, this was just an apparent bug in SourceTree, and perhaps a feature request/suggestion as well.

I installed a different tool (instead of SourceTree) and my problem was solved.

Anyway, thanks for your reply. 

Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 17, 2016

.. or perhaps I didn't get your question correctly ...

Anyway: your problem is solved!

Cheers

Johannes

Prabhmeet S July 18, 2018

@Valgardur Gudjo   : Can you please advise how you solved this problem. I reckon I have the same issue.  Thank you.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events