我该如何将一个任意分支归档? [英] How can I git archive an arbitrary branch?

查看:75
本文介绍了我该如何将一个任意分支归档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git checkout master
git archive stage | tar -czf archive.tar.gz htdocs
# archives master because it's checked out.

无论当前处于何种状态,我如何归档舞台分支?

How can I archives the stage branch, regardless of the current I'm on?

推荐答案

git archive会创建一个tar归档文件,因此您不需要管道输出tar文件,实际上它并没有达到您期望的效果。您正在创建stage分支的tar归档文件,并将其管道传输到一个普通的tar命令,该命令不使用其标准输入,而是在工作中创建自己的 htdocs 存档树,独立于git。

git archive creates a tar archive so you don't need to pipe its output tar, indeed it's not doing what you expect. You are creating an tar archive of the stage branch and piping it to a normal tar command which doesn't use its standard input but just creates its own archive of htdocs in the working tree, independently of git.

尝试:

Try:

git archive stage >stage.tar

或者对于压缩存档:

git archive stage | gzip >stage.tar.gz

只需将htdocs子文件夹归档即可:

To just archive the htdocs subfolder you can do:

git archive stage:htdocs | gzip >stage-htdocs.tar.gz

或者在存档中包含文件夹名称:

or, to include the folder name in the archive:

git archive --prefix=htdocs/ stage:htdocs | gzip >stage-htdocs.tar.gz

或更简单:

or more simply:

git archive stage htdocs | gzip >stage-htdocs.tar.gz

这篇关于我该如何将一个任意分支归档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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