gpt4 book ai didi

git - Bare 和非 Bare 存储库之间的实际区别是什么?

转载 作者:IT王子 更新时间:2023-10-29 01:16:40 47 4
gpt4 key购买 nike

我一直在阅读有关 Git 中裸和非裸/默认存储库的信息。我一直无法很好地(理论上)理解它们之间的区别,以及为什么我应该“推送”到裸存储库。这是交易:

目前,我是唯一一个在 3 台不同计算机上从事一个项目的人,但以后会有更多人参与其中,所以我使用 Git 进行版本控制。我在所有计算机上克隆裸仓库,当我在其中一台计算机上完成修改后,我将更改提交并推送到裸仓库。根据我的阅读,裸存储库没有“工作树”,因此如果我克隆裸存储库,我将没有“工作树”。

我猜工作树存储了项目的提交信息、分支等。那不会出现在裸仓库中。所以对我来说,使用工作树将提交“推送”到 repo 似乎更好。

那么,我为什么要使用裸存储库,为什么不呢?实际区别是什么?我想,这对参与项目的更多人没有好处。

您从事此类工作的方法是什么?有什么建议吗?

最佳答案

裸仓库和非裸仓库的另一个区别是裸仓库没有默认的远程origin 仓库:

~/Projects$ git clone --bare test bare
Initialized empty Git repository in /home/derek/Projects/bare/
~/Projects$ cd bare
~/Projects/bare$ git branch -a
* master
~/Projects/bare$ cd ..
~/Projects$ git clone test non-bare
Initialized empty Git repository in /home/derek/Projects/non-bare/.git/
~/Projects$ cd non-bare
~/Projects/non-bare$ git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master

来自 git clone --bare 的手册页:

Also the branch heads at the remote are copied directly to corresponding local branch heads, without mapping them to refs/remotes/origin/. When this option is used, neither remote-tracking branches nor the related configuration variables are created.

据推测,在创建裸仓库时,Git 假定裸仓库将作为多个远程用户的源仓库,因此它不会创建默认的远程源。这意味着基本的 git pullgit push 操作将不起作用,因为 Git 假设没有工作区,您不打算提交任何更改到裸存储库:

~/Projects/bare$ git push
fatal: No destination configured to push to.
~/Projects/bare$ git pull
fatal: /usr/lib/git-core/git-pull cannot be used without a working tree.
~/Projects/bare$

关于git - Bare 和非 Bare 存储库之间的实际区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5540883/

47 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com