简体   繁体   English

如何从 git 存储库中仅克隆一个分支的工作目录,而不使用.git 文件夹

[英]How to clone only a branch's working directory from a git repository without .git folder

Is there any git command that allow me to "clone" from a git repository but only the working directory of specified branch is cloned without.git folder that has all logs and version history?是否有任何 git 命令允许我从 git 存储库“克隆”,但只有指定分支的工作目录被克隆,而没有.git 文件夹包含所有日志和版本历史记录?

There are few reasons to work with multiple working directory on single.git repo.在 single.git repo 上使用多个工作目录的理由很少。 Reason 1: I have few branch in a git, I want to work and see these branch at the same time without git checkout that may override files in branches.原因 1:我在 git 中的分支很少,我想在没有 git 检出的情况下同时工作并查看这些分支,这可能会覆盖分支中的文件。 Reason 2: I want to make a software release of particular branch but don't want to disturb the branch that I am working.原因 2:我想发布特定分支的软件,但不想打扰我正在工作的分支。

As per OP's latest comment:根据 OP 的最新评论:

Why don't you make another clone ( or just copy the existing repo) and checkout another branch in that?你为什么不做另一个克隆(或者只是复制现有的仓库)并在其中签出另一个分支?

Git-Archive can help you: Git-Archive 可以帮助您:

Sample from the docs:来自文档的示例:

git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)

You can also use the --remote flag to get it from a remote archive.您还可以使用--remote标志从远程存档中获取它。

http://www.kernel.org/pub/software/scm/git/docs/git-archive.html http://www.kernel.org/pub/software/scm/git/docs/git-archive.html

On Linux (or Windows too, if you install a commandline tar client ):在 Linux(或 Windows 上,如果您安装命令行tar客户端):

git archive <commitish> | tar -x -C /path/to/folder

Basically, this tells git to build an archive (tarball) of the source tree at revision <commitish> and then pipes it through tar which extracts it into a folder.基本上,这告诉 git 在修订版<commitish>处构建源树的存档(tarball),然后通过 tar 将其提取到文件夹中。

Unfortunately, git doesn't currently support this directly.不幸的是, git目前不直接支持这个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM