没有 .git 目录的 Git 克隆

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11497457/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:07:24  来源:igfitidea点击:

Git clone without .git directory

gitversion-controlgit-clone

提问by Justin

Is there a flag to pass to gitwhen doing a clone, say don't clone the .gitdirectory? If not, how about a flag to delete the .gitdirectory after the clone?

git进行克隆时是否有要传递的标志,例如不要克隆.git目录?如果没有,.git克隆后删除目录的标志如何?

回答by Adam Dymitruk

Use

git clone --depth=1 --branch=master git://someserver/somerepo dirformynewrepo
rm -rf ./dirformynewrepo/.git
  • The depth option will make sure to copy the least bit of history possible to get that repo.
  • The branch option is optional and if not specified would get master.
  • The second line will make your directory dirformynewreponot a Git repository any more.
  • If you're doing recursive submodule clone, the depth and branch parameter don't apply to the submodules.
  • 深度选项将确保复制尽可能少的历史记录以获得该回购。
  • 分支选项是可选的,如果未指定,将获得 master。
  • 第二行将使您的目录dirformynewrepo不再是 Git 存储库。
  • 如果您正在进行递归子模块克隆,则深度和分支参数不适用于子模块。

回答by Huang Tao

since you only want the files, you don't need to treat it as a git repo.

由于您只需要这些文件,因此您无需将其视为 git 存储库。

rsync -rlp --exclude '.git' user@host:path/to/git/repo/ .

and this only works with local path and remote ssh/rsync path, it may not work if the remote server only provides git:// or https:// access.

并且这只适用于本地路径和远程 ssh/rsync 路径,如果远程服务器只提供 git:// 或 https:// 访问,它可能不起作用。

回答by Erik Vullings

Alternatively, if you have Node.jsinstalled, you can use the following command:

或者,如果您安装了Node.js,则可以使用以下命令:

npx degit GIT_REPO

npx degit GIT_REPO

npxcomes with Node, and it allows you to run binary node-based packages without installing them first (alternatively, you can first install degitglobally using npm i -g degit).

npxNode 附带,它允许您运行基于二进制节点的软件包,而无需先安装它们(或者,您可以先degit使用 全局安装npm i -g degit)。

Degitis a tool created by Rich Harris, the creator of Svelte and Rollup, which he uses to quickly create a new project by cloning a repository without keeping the git folder. But it can also be used to clone any repo once...

Degit是由 Svelte 和 Rollup 的创建者 Rich Harris 创建的工具,他用它来通过克隆存储库而不保留 git 文件夹来快速创建新项目。但它也可以用来克隆任何仓库一次......

回答by Erik Vullings

You can always do

你总能做到

git clone git://repo.org/fossproject.git && rm -rf fossproject/.git