Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
Community Members
Community Events
Community Groups

retrieve files from a specific commit

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

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".


0 votes

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 ...

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..

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...

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. 

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

Anyway: your problem is solved!



@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

Atlassian Community Events