制作远程 git 存储库的本地副本
我对版本控制的术语或实践和程序不是很熟悉。
这是我想要做的:
我想从互联网上的 git 存储库下载一个文件夹。克隆是正确的方法吗?克隆不会保留不必要的元数据文件吗?有没有办法进行“干净”下载?
我想设置一个包含此文件夹的本地存储库,我现在可以在其中使用版本控制。也就是说,当我进行提交时,我的本地存储库会更新。
最后,我希望这个本地存储库可以在本地网络上访问,以便我也可以从 LAN 上的任何其他计算机上下载它。
I am not very familiar with the terminology or practices and procedures of version control.
Here is what I want to do :
I want to download a folder from a git repository from the Internet. Is cloning the right way to do it ? WOn't cloning keep the unnecessary meta-data files ? Is there a way to do a "clean" download ?
I want to set up a local repository that contains this folder on which I can now use version control. That is, when I do a commit, my local repository gets updated.
Finally, I want this local repo to be accessible on the local network, so that I can download it from any other machine on the LAN too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请参阅 Git 参考的
git clone
。请参阅 git 本地协议。
如果您不熟悉这些操作,我建议您按照 git immersion< 提出的简单练习进行操作/强>。
See
git clone
of Git Reference.See git local protocol.
If you are not familiar with those operations, I would recommend you to follow the simple exercices proposed by git immersion.
您无法从 git 存储库下载单个文件或文件夹,因为 git 跟踪整个项目的完整状态,而不仅仅是单个文件。可以从远程存储库仅克隆有限的修订集(称为浅克隆),但此类克隆仅限于有限的操作集,例如,您无法从浅克隆克隆,或从这样的回购协议。
如果 git repo 的大小困扰您,您可以使用 git gc 来让 git 重新组织对象数据库,这有时可以获得大小改进。
当您想要拥有本地缓存时,可以使用 git clone --mirror $REMOTE_URL 来创建一个克隆,该克隆
您可以从这个本地缓存存储库克隆新的工作存储库,或者直接推送到上游存储库(您需要在你的工作副本中
git remote add upper $REMOTE_URL
来添加上游仓库的链接,之后你可以git push upper
),或者你也可以推送到本地缓存repo,并推送到上游repo从那里。You can't download single files or folders from a git repo, since git tracks the full state of a project as a whole, not just single files. There is a possibility to clone only a limited set of revisions (called shallow clone) from a remote repositoy, but such clones are restricted to a limited set of operations, for example you can't clone from a shallow clone, or push something from such a repo.
If the size of a git repo bothers you, you can
git gc
to make git reorganize the object database, which sometimes can get size improvements.When you want to have a local cache, you can use
git clone --mirror $REMOTE_URL
to create a clone, whichYou can clone new working repos from this local cache repo, and either push directly into the upstream repo (you need to
git remote add upstream $REMOTE_URL
in your working copy to add the link to the upstream repo, afterwards you cangit push upstream
), or you can push into the local cache repo, and push to the upstream repo from there.虽然
git clone
适合步骤 1 和 2。 2、您可能需要阅读一些 git 书籍,例如 Progit / Community 书籍等,以正确了解步骤 3 的最佳方法和 git 哲学。Git 作为分布式 VCS,努力避免您的“可在本地网络上访问的本地存储库”可能建议的“单一中央存储库”。您可以在网络上拥有一个裸存储库,这允许许多从中推送/拉取,但这与在网络上拥有本地存储库(带有工作目录)和不同>只有您像本地驱动器一样使用它。
While
git clone
is the right for steps 1 & 2, you may need to have a read of a few of the git books e.g. Progit / Community book etc. to get a proper flavour of the best approach to step 3, and the git philosophy.Git, as a distributed VCS, tries hard to avoid the "single central repository" that your "local repo to be accessible on the local network" might suggest. You can have a bare repo on the network, which allows many to push/pull from it, but this isn't the same as having your local repo on the network, with working directory, and only you using it as if it were a local drive.
是的,“git克隆”是正确的选择。这将为您提供所有数据并允许您进行提交。只要新的存储库在 LAN 上可见,其他计算机就应该能够从中克隆。
Yes 'git clone' is the way to go. This will get you all the data and allow you to do commits. As long as the new repo is visible on the LAN, other computers should be able to clone from it as well.