如何使用 git-archive 导出特定提交?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11018411/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I export a specific commit with git-archive?
提问by SSEMember
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 存储库,但我遇到了问题。我试过的是
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.
解压缩后,它们最终完全相同。我不知道为什么或如何解决它。
回答by Todd A. Jacobs
The Problem
问题
In both your examples, you are exporting the tip of master. Take out your flags and arguments, and you have:
在您的两个示例中,您都在导出master的提示。取出你的标志和参数,你有:
git archive master
In other words, you're explicitly doing this to yourself by specifying whatever is stored in .git/refs/heads/masteras your tree-ish.
换句话说,您通过将.git/refs/heads/master 中存储的任何内容指定为您的树状来明确地对自己执行此操作。
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:
如果您想导出不同的提交,您需要根据gitrevisions(7)提供一个 tree-ish 。例如,要导出提交29435bc,您可以指定:
git archive --format zip --output /full/path/to/zipfile.zip 29435bc
回答by zheng li
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 的预期行为。远程 Git 存储库不允许客户端访问任意 SHA1。请求的对象应该通过引用(即文件名)访问。