Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
476 views
in Technique[技术] by (71.8m points)

repository - How do I export a specific commit with git-archive?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...