git克隆 不带目录,git clone,忽略一个目录

博主想在WordPress安装上测试,需快速复制仓库,但上传目录过大想忽略,且不想一直将其加入.gitignore。提出类似git clone --ignore wp-content/uploads的需求,解决方案是使用稀疏检出,包括初始化仓库、添加远程仓库、启用稀疏检出、配置子树并拉取。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I'm trying to test something on a wordpress install. In doing so, I'd like to quickly replicate the repo. However, the upload directory (wp-content/uploads) is massive, so I'd like to ignore it.

Note: I don't want to .gitignore this directory all the time, just for this scenario.

Basically, I'd like a command like this pseudo code: git clone --ignore wp-content/uploads.

Is the best way to add that directory to .gitignore, clone, and then revert .gitignore? Or is there a better method?

解决方案

A bit late to the party, but: Don't you want a sparse checkout?

mkdir && cd

git init

git remote add –f

Enable sparse-checkout:

git config core.sparsecheckout true

Configure sparse-checkout by listing your desired sub-trees in .git/info/sparse-checkout:

echo some/dir/ >> .git/info/sparse-checkout

echo another/sub/tree >> .git/info/sparse-checkout

Checkout from the remote:

git pull

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值