制作远程 git 存储库的本地副本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7130639/
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
Make a local copy of a remote git repository
提问by AnkurVj
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.
我想从 Internet 上的 git 存储库下载一个文件夹。克隆是正确的方法吗?克隆不会保留不必要的元数据文件吗?有没有办法进行“干净”的下载?
我想设置一个包含此文件夹的本地存储库,我现在可以在其中使用版本控制。也就是说,当我提交时,我的本地存储库会更新。
最后,我希望这个本地存储库可以在本地网络上访问,以便我也可以从 LAN 上的任何其他机器下载它。
采纳答案by VonC
- Cloning is the right way, but will download all the directories of your remote Git repo.
Seegit clone
of Git Reference. - The clone command will create a repo with a working tree already checked out in it, and a .git representing your full repo
- You need to have at least a shared path in order for other to clone/pull/push your repo.
See git local protocol.
- 克隆是正确的方法,但会下载远程 Git 存储库的所有目录。
请参阅git clone
Git 参考。 - clone 命令将创建一个 repo,其中已经签出一个工作树,一个 .git 代表你的完整 repo
- 您至少需要有一个共享路径,以便其他人克隆/拉/推您的存储库。
请参阅git 本地协议。
If you are not familiar with those operations, I would recommend you to follow the simple exercices proposed by git immersion.
如果您不熟悉这些操作,我建议您遵循git immersion提出的简单练习。
回答by foobar
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.
您不能从 git 存储库下载单个文件或文件夹,因为 git 跟踪整个项目的完整状态,而不仅仅是单个文件。有可能从远程存储库中只克隆一组有限的修订(称为浅克隆),但此类克隆仅限于一组有限的操作,例如您不能从浅克隆中克隆,或从这样的回购。
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.
如果 git repo 的大小困扰你,你可以git gc
让 git 重新组织对象数据库,这有时可以获得大小改进。
When you want to have a local cache, you can use git clone --mirror $REMOTE_URL
to create a clone, which
当你想要一个本地缓存时,你可以使用git clone --mirror $REMOTE_URL
创建一个克隆,它
- tracks all remote branches (see What's the difference between git clone --mirror and git clone --bare)
- is a bare repo (=has no working copy, see gitready.comor this SO questionwhy this is a good idea for a cache repo)
- act as a local cache, or a staging repo
- 跟踪所有远程分支(请参阅git clone --mirror 和 git clone --bare 之间的区别是什么)
- 是一个裸仓库(=没有工作副本,请参阅gitready.com或这个 SO 问题为什么这是缓存仓库的好主意)
- 充当本地缓存或临时存储库
You 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 can git push upstream
), or you can push into the local cache repo, and push to the upstream repo from there.
你可以从这个本地缓存仓库克隆新的工作仓库,或者直接推送到上游仓库(你需要git remote add upstream $REMOTE_URL
在你的工作副本中添加到上游仓库的链接,之后你可以git push upstream
),或者你可以推送到本地缓存回购,并从那里推送到上游回购。
回答by Philip Oakley
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 clone
是第 1 步和第 2 步的正确选择,但您可能需要阅读一些 git 书籍,例如 Progit / Community book 等,才能正确了解第 3 步的最佳方法和 git 哲学。
Git, as a distributedVCS, 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 manyto push/pull from it, but this isn't the same as having your local repo on the network, with working directory, and only youusing it as if it were a local drive.
Git,作为一个分布式VCS,努力避免“单一中央存储库”,您的“本地存储库可在本地网络上访问”可能会建议。您可以在网络上拥有一个裸存储库,它允许许多人从中推/拉,但这与在网络上拥有本地存储库不同,具有工作目录,并且只有您像使用它一样使用它本地驱动器。
回答by user885074
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.
是的 'git clone' 是要走的路。这将为您提供所有数据并允许您进行提交。只要新的存储库在 LAN 上可见,其他计算机也应该能够从中克隆。