28

I asked a similar question before, but it was answered inadequately so I thought I would ask again here but providing more information. I need to get different and older versions of a git repository and I'm having trouble with that. What I've tried is

git checkout master~X 

git archive --format zip --output /full/path/to/zipfile.zip master 

git checkout master 


git checkout master~Y 

git archive --format zip --output /full/path/toDifferent/zipfile.zip master 

git checkout master 

After unzipping both, they end up being exactly the same. I can't figure out why or how to fix it.

Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
SSEMember
  • 2,103
  • 4
  • 20
  • 28

2 Answers2

52

The Problem

In both your examples, you are exporting the tip of master. Take out your flags and arguments, and you have:

git archive master

In other words, you're explicitly doing this to yourself by specifying whatever is stored in .git/refs/heads/master as your tree-ish.

The Solution

You need to provide a tree-ish in accordance with gitrevisions(7) if you want to export a different commit. For example, to export commit 29435bc, you could specify:

git archive --format zip --output /full/path/to/zipfile.zip 29435bc
Karl Wilbur
  • 5,898
  • 3
  • 44
  • 54
Todd A. Jacobs
  • 81,402
  • 15
  • 141
  • 199
  • 2
    Yep, I was correct in determining why I am an idiot. Thanks for confirming it and giving me something to accept though. I appreciate it :) – SSEMember Jun 13 '12 at 16:43
  • 4
    I am using second commend `git archive --format zip --output /full/path/to/zipfile.zip 29435bc` but it export the whole source code, could you suggest me whats is the issue My exact comment is `$ git archive --format zip --output C:/Users/anishanth/zipfile.zip 2dbbc28 ` – Anto S Aug 11 '16 at 07:37
  • calling git archive via remote With a sha1 (f.x. `git archive --remove=file:///var/git/repo/ --output /tmp/specific_ref.tar `) will not work as git archive on remote will only give out the HEAD ref. If you need an archive of a specific ref, you need to perform a git clone and then call git archive from withing that working copy (i.e. leaving out the remote part of the command, fx: `git archive --output /tmp/specific_ref.tar `) – mschr Jun 28 '19 at 13:22
3

Resolution

This is an expected behaviour for the newest versions of Git. Remote Git repositories do not allow clients to access arbitrary SHA1s. The requested objects should be accessed by a ref (i.e. file name).

git-upload-archive-archiver-died-with-error

zheng li
  • 501
  • 1
  • 4
  • 10
  • While you are correct, in the original question, the asker wasn't referencing a remote so this response isn't really relevant. The `git-archive` was executed within the repo itself. In the case of the original question, the `git-archive` command was explicitly exporting the same tree-ish (i.e: `master`) rather than the intended tree-ish (`master~X` and `master~Y`). – Karl Wilbur May 02 '18 at 14:59