git复制特定版本的存储库 [英] git copy particular version of repository

查看:91
本文介绍了git复制特定版本的存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是git的新手,如果这是一个愚蠢的问题,请原谅我. 我有一个git存储库,需要将存储库的特定版本复制到其自己的单独目录中.复制的版本本身不必是git存储库,我不需要或不需要历史记录或.git文件夹,只是特定提交的存储库是什么样子.

I'm new to git so forgive me if this is a dumb question. I have a git repository and I need to copy a particular revision of the repository to its own separate directory. The copied version doesn't need to be a git repository itself, I don't need or want the history or the .git folder, just what the repository looked like for a particular commit.

所以说我这样做:

mkdir blah
cd blah
git init
touch flim0
git add .
git commit -a -m "First commit"
touch flim1
git add .
git commit -a -m "Second commit"

mystery-command ~/some-folder 4be82b42cc91ac3801ad72036cec5f88b6a13bd7

其中4be82b42cc91ac3801ad72036cec5f88b6a13bd7是首次提交"的哈希值,我希望〜/some-folder成为仅包含文件flim0的目录.

Where 4be82b42cc91ac3801ad72036cec5f88b6a13bd7 is the hash of "First commit", I want ~/some-folder to be a directory that contains only the file flim0.

这样容易/可行,而不必克隆存储库,然后签出特定的修订版本,然后从克隆的存储库中删除.git吗?

Is this easy/possible without having to clone the repository then checkout a particular revision then delete .git from the cloned repository?

推荐答案

 git archive master >specificversion.tar

用提交标识符替换主文件

replace master by a commit identifier

如果您要立即签出",请考虑

If you want to immediately 'check it out', consider

 git archive master | (cd /tmp/exportlocation && tar x)

git archive(与往常一样)带有大量其他有用的选项

git archive (as usual) comes with a load of other useful options

这篇关于git复制特定版本的存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆