git Git的本地仓库和远程仓库——混淆概念
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13072111/
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
Git's local repository and remote repository -- confusing concepts
提问by zell
If I understand correctly, Git has two sorts of repositories: one called local, another called remote. My questions are extremely naive ones about the two types of repositories.
如果我理解正确的话,Git 有两种存储库:一种称为本地,另一种称为远程。我的问题是关于这两种类型的存储库的非常幼稚的问题。
Is that correct to say
这样说对吗
Git local repository is the one on which we will make local changes, typically this local repository is on our computer.
Git remote repository is the one of the server, typically a machine situated at 42 miles away.
Git 本地存储库是我们将对其进行本地更改的存储库,通常此本地存储库位于我们的计算机上。
Git 远程存储库是其中一个服务器,通常是位于 42 英里外的机器。
Another question: some tutorial shows me this workflow
另一个问题:一些教程向我展示了这个工作流程
- mkdir myproject
- cd myproject
- git init
- touch README
- git add README
- git commit -a -m "
- mkdir 我的项目
- 光盘我的项目
- git初始化
- 触摸自述文件
- git 添加自述文件
- git commit -a -m"
I see that git init
creates myproject a local repository. What I don't understand is the
git commit
command. If I have not yet set a remote repository, how can Git know where to commit my README
file??
我看到将git init
myproject 创建为本地存储库。我不明白的是
git commit
命令。如果我还没有设置远程仓库,Git 怎么知道在哪里提交我的README
文件??
I hope I was clear.
我希望我很清楚。
[EDIT] The way I am using Git might be different from others: I use a private Git repository to backup my codes. So I think I do need a remote repository. The local repository should be nonsense in this case. Am I right? Thanks for your clarification. These are the most naive questions that I cannot find replies anywhere else...
[编辑] 我使用 Git 的方式可能与其他人不同:我使用私有 Git 存储库来备份我的代码。所以我想我确实需要一个远程存储库。在这种情况下,本地存储库应该是无稽之谈。我对吗?感谢您的澄清。这些是我在其他任何地方都找不到答案的最幼稚的问题...
采纳答案by agmin
What makes git so awesome is it's a distributedversion control system. Your local repository has exactly the same features and functionality as any other git repository. So a git repo on a server is the same as a git repo on github (granted github adds additional features, but at its core you're dealing with git repos) which is the same as your coworker's local repo.
git 如此出色的原因在于它是一个分布式版本控制系统。您的本地存储库与任何其他 git 存储库具有完全相同的特性和功能。因此,服务器上的 git repo 与 github 上的 git repo 相同(授予 github 添加了附加功能,但在其核心,您正在处理 git repos),这与您同事的本地 repo 相同。
So why is that awesome? Because there is no central repo you have to have access to to do your work. You can commit, branch and party on your own repo on your local machine even without internet access. Then, when you have a connection again, you can push your changes to any other git repo you have access to. So while most people treat a particular repo as the central repo, that's a process choice, not a git requirement.
那为什么这么棒?因为没有中央存储库,您必须有权访问才能完成工作。即使没有互联网访问,您也可以在本地机器上提交、分支和参与您自己的存储库。然后,当您再次建立连接时,您可以将更改推送到您有权访问的任何其他 git 存储库。因此,虽然大多数人将特定的 repo 视为中央 repo,但这是一个过程选择,而不是 git 要求。
The point of all that was to state (as others have) that you're committing your README to your local repo. Then, whenever you choose, you can push changes from your local repo to any other repo. It's pretty nifty!
所有这一切的重点是声明(就像其他人一样)您将自述文件提交到您的本地存储库。然后,无论何时选择,您都可以将更改从本地存储库推送到任何其他存储库。它很漂亮!
回答by Bishoy Hanna
As I'm experiencing exactly the same questions like yours (coming from VSSand TFSmindset) and during the last 3 days started to understand. I would believe that these kind of diagrams would be more helpful to understand the whole picture for anyone else trapped there.
因为我遇到了与您完全相同的问题(来自VSS和TFS心态)并且在过去 3 天内开始理解。我相信这些图表会更有助于其他被困在那里的人了解整体情况。
from: https://greenido.files.wordpress.com/2013/07/git-local-remote.png?w=696&h=570
来自:https: //greenido.files.wordpress.com/2013/07/git-local-remote.png?w=696&h=570
Another one, from: https://wiki.lsr.ei.tum.de/lib/exe/fetch.php?media=nst/programming/git_flow.jpg&w=500&tok=e87798
另一个,来自:https: //wiki.lsr.ei.tum.de/lib/exe/fetch.php?media=nst/programming/git_flow.jpg&w=500&tok=e87798
回答by SLaks
Your quoted statement is correct.
你引用的陈述是正确的。
You don't need to have a remote repository at all.
You can have the full git experience, with commits, branches, merges, rebases, etc, with only a local repository.
您根本不需要远程存储库。
您可以拥有完整的 git 体验,包括提交、分支、合并、变基等,只需一个本地存储库。
The purpose of a remote repository (eg, GitHub) is to publish your code to the world (or to some people) and allow them to read or write it.
远程存储库(例如,GitHub)的目的是将您的代码发布给全世界(或某些人)并允许他们阅读或编写它。
The remote repository is only involved when you git push
your local commits to a remote repository, or when you git pull
someone else's commits from it.
远程存储库仅在git push
您本地提交到远程存储库或git pull
其他人从它提交时才涉及。
回答by Quentin
If I have not yet set a remote repository, how can Git know where to commit my README file??
如果我还没有设置远程仓库,Git 怎么知道在哪里提交我的 README 文件??
You are committing to your local repository (which is a proper repository with its own change control; it isn't just a local checkout … since you created it locally, it isn't evena local checkout!).
您正在提交到您的本地存储库(这是一个具有自己的更改控制的适当存储库;它不仅仅是本地检出……因为您在本地创建它,它甚至不是本地检出!)。
If you want to send changes to a remote repository (to back them up, make them available to other members of the team, or publish them to the world), you must pushthem.
如果您想将更改发送到远程存储库(以对其进行备份、将它们提供给团队的其他成员或将它们发布到全世界),您必须推送它们。
回答by velocity
The need of a remote repository instance on github for example is only to share the code with other programmers, since they can' just access your git repo (unless they connect to your pc using your ip an still then they only have access to your changes only but not the changes of other programmers), that' why commit your changes from you local repository to the remote/central repo so that other developers can check them out and finally have end up wih a same state of the software. But at the end if you are the only developer, you don't really need a remote/central repo.
例如,在 github 上需要远程存储库实例只是为了与其他程序员共享代码,因为他们只能访问您的 git repo(除非他们使用您的 ip 连接到您的电脑,然后他们只能访问您的更改只是但不是其他程序员的更改),这就是为什么将您的更改从本地存储库提交到远程/中央存储库,以便其他开发人员可以检查它们并最终获得相同状态的软件。但最后,如果你是唯一的开发人员,你真的不需要远程/中央仓库。