我发现了很多关于克隆存储库并立即检查给定提交 ID 的问题/答案。简单的方法:
git clone <URL> working-copy
cd working-copy; git checkout <COMMIT-ID>
Run Code Online (Sandbox Code Playgroud)
通过分支机构,您可以git clone -b <BRANCH> <URL>
使用分支,您还可以进行浅克隆,这使得克隆速度更快,但您无法再检出任意 ID。
所以我的问题是:有没有一种方法可以对给定的 URL/提交 ID 进行浅表克隆,而无需在远程创建分支?
不同类型的远程存储库有区别吗?(例如本地文件系统、BitBucket、GitHub、GitLab 等)
我们读到了有关git狭窄克隆 的内容。假设我们想在极端情况下使用这一新功能,并且只需使用最小的带宽即可从大型远程存储库编辑一个文件并推迟我们的提交。
人们发现的唯一示例是
git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1
让我们添加 --深度 1 以节省更多数据流量和磁盘空间。但是我们如何指定单个远程 文件
而不触发“似乎不是 git 存储库”错误呢?git 版本 2.17.0.290。
我得到了一个 git 存储库,它是通过运行命令 git clone --mirror 生成的(并随后压缩)。我想知道如何以可以开始编程的方式打开该项目。
\n\n包根目录如下所示:
\n\nmax$ tree\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 HEAD\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 config\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 description\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 hooks\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 applypatch-msg.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 commit-msg.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 post-update.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pre-applypatch.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pre-commit.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pre-push.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pre-rebase.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pre-receive.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 prepare-commit-msg.sample\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 update.sample\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 info\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 exclude\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 objects\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 info\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pack\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 pack-0357e8f849278dd87fa3f57757c32d2f4afde634.idx\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 pack-0357e8f849278dd87fa3f57757c32d2f4afde634.pack\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 packed-refs\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 refs\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 heads\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 tags\n\n8 directories, 17 files\nRun Code Online (Sandbox Code Playgroud)\n 我有一台本地计算机,上面有同一个 GIT 存储库的多个副本,每个副本针对不同的用户。所以它可能看起来像这样:
/home/userA/BigRepository
/home/userB/BigRepository
/home/userC/BigRepository
/home/userD/BigRepository
/home/userE/BigRepository
Run Code Online (Sandbox Code Playgroud)
假设每个存储库使用约 2-3GB,20 个用户将使用 40-60GB 不必要的冗余数据。用户可能会在他们的私有分支上开发一些东西,但大多数数据仍然是冗余的。这就是为什么我想优化磁盘使用。
我想知道解决这个问题的最佳方法是什么。
我已经检查过的内容:
git clone --local- 每个存储库将与裸存储库共享 .git/objects,但这意味着 .bare 存储库必须在本地可用(所以它不能是 GitHub,对吧?)git clone --depth <n>- 这将减少存储库的大小,但也会将本地历史记录减少到 n 个对象。git clone --shallow-since- 据我了解,它的工作方式与--depth选项类似,但会存储自指定时间以来的提交。git clone --separate-dir- 我自己的想法是使用同一个地方来存储所有 .git 目录。(因此,在进行克隆时,20 个存储库中的每一个都会链接到同一个位置。尚不知道是否可能,只是分享我的想法。是否--depth意味着存储库最多有 n 次提交,或者仅在克隆时检查,然后存储库可以随时间增长?
我想浅克隆存储库的一部分:只有 1 个功能分支(包括从 分支以来的所有提交)和之前的main一些提交。main
我已经尝试过git clone $repo --depth=N --branch=$feature正确检查 $feature 的浅克隆,并且假设我选择足够大的深度返回到分支点。
拉入 main 的咒语是什么?
本质上我希望能够做到:
git clone --branch=$feature
BASE=$(git merge-base $feature origin/main)
echo git rev-parse $BASE^
echo git rev-parse $BASE^^
echo git rev-parse $BASE^^^
Run Code Online (Sandbox Code Playgroud)
告诉我在分支之前发生的几次提交的 SHA1。
我在git下有一个大型的C项目.其他人有相同的C项目,但他没有使用git.
我们俩都是从相同的基线开始的,但我只是做了git init/ git add .并开始使用git.
我想将我的git托管更改合并到其他分支并在他的项目文件夹中使用init git,这样我们就会同步并使用git.
你会怎么用git做这个?
所以我只是设置了一个Amazon EC2实例.并安装了git ..
sudo yum install git
Run Code Online (Sandbox Code Playgroud)
然后我用github设置我的ssh密钥.现在,当我尝试将我的repo克隆到/ var/www/html文件夹时,我收到此错误..
fatal: could not create work tree dir 'example.com'.: Permission denied
Run Code Online (Sandbox Code Playgroud)
当我以root身份运行时......
Cloning into 'example.com'...
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)
但我确保我的github公钥与我的〜/ .ssh/id_rsa.pub键匹配.这里有什么我想念的吗?
因为无法克隆git repo而遇到了问题.它开始运行然后取消一半.我当前的git repo大小是53.7 MB Git版本在服务器和我的遥控器上是1.7.12.4.
错误如下:
MacBook-Pro:htdocs macbook$ git clone myrepo@mysite.com:~/opt/git/myrepo.git
Cloning into 'myrepo'...
zcardepo@zcardepot.com's password:
remote: Counting objects: 8888, done.
remote: Compressing objects: 100% (7185/7185), done.
Write failed: Broken pipe267/8888), 1.03 MiB | 1001.00 KiB/s
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed
Run Code Online (Sandbox Code Playgroud)
我创建了一个新的新回购,克隆就好了.一旦我将我的站点文件添加到它并将它们推送到远程.我再也无法从中克隆了.但我可以从中汲取它.
我添加了这个没有运气:
[core]
compression = -1
[pack]
windowMemory = 10m
packSizeLimit = 20m
Run Code Online (Sandbox Code Playgroud)
我试着将这两者都提升到更高的价值.没运气
我也尝试在远程仓库上运行git gc --aggressive和git gc --prune.
先决条件:
现在我们要从git存储库部署应用程序.这应该很简单,但事实并非如此.
- name: Clone app repo
git:
repo: githost:org/repo.git
dest: /some/location
version: HEAD
force: yes
ssh_opts: -o StrictHostKeyChecking=no
notify:
- Restart app
Run Code Online (Sandbox Code Playgroud)
githost是我们的.ssh/config中的一个条目
以上任务有效.但是(当然)存储库被克隆为执行该剧本的用户.我们需要的是:
zaphodzaphod允许读取文件.我们正在谈论0600/0700权限.以下任务将不起作用,因为通过使用become我们将丢失转发的ssh密钥,因此git身份验证将失败:
- name: Clone app repo
git:
repo: githost:org/repo.git
dest: /some/location
version: HEAD
force: yes
ssh_opts: -o StrictHostKeyChecking=no
notify:
- Restart app
become: yes
become_user: zaphod
Run Code Online (Sandbox Code Playgroud)
以下变体将首先调用处理程序,该处理程序在(重新)启动应用程序之前更改结帐的所有权:
- name: Clone app repo
git:
repo: githost:org/repo.git
dest: /some/location
version: HEAD
force: …Run Code Online (Sandbox Code Playgroud) 我想,以反映所有可用的本地存储库refs,包括refs/notes/*.但是,未按预期克隆注释.
要重现该问题,请在空目录中执行以下命令:
$ git init repo && cd repo
$ git commit --allow-empty -m 'initial commit'
$ git notes add -m 'Initial commit on empty repo' HEAD
$ git clone --mirror .git ../mirror
Run Code Online (Sandbox Code Playgroud)
获取refs之间的差异显示notes镜像存储库中缺少:
$ diff repo/.git/refs mirror/refs
Common subdirectories: repo/.git/refs/heads and mirror/refs/heads
Common subdirectories: repo/.git/refs/tags and mirror/refs/tags
Only in repo/.git/refs: notes
Run Code Online (Sandbox Code Playgroud)
git -C mirror fetch即使在fetch = +refs/*:refs/*中指定,也不会获取注释mirror/config.
现在的问题是:我有什么遗失的东西吗?我正在使用git 2.3.0
git ×10
git-clone ×10
github ×2
amazon-ec2 ×1
ansible ×1
clone ×1
commit ×1
diskspace ×1
git-branch ×1
git-merge ×1
git-mirror ×1
git-pull ×1
git-remote ×1
linux ×1
mirror ×1