Git 工作流程:没有服务器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5947064/
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 Workflow: Without a server
提问by Ben Page
git is supposed to be a decentralized system, but all the tutorials and best practice workflows I have found on google suggest using a server (usually github, or else set up your own)
git 应该是一个分散的系统,但是我在 google 上找到的所有教程和最佳实践工作流程都建议使用服务器(通常是 github,或者设置自己的)
I am using git for small personal projects (2-3 people), where can I find a best practice workflow for syncing changes directly between the team members machines. Alternatively, what are some compelling arguments for why I should avoid this and instead set up a 'central' server?
我正在将 git 用于小型个人项目(2-3 人),在哪里可以找到在团队成员机器之间直接同步更改的最佳实践工作流程。或者,有什么令人信服的论据可以说明为什么我应该避免这种情况而是建立一个“中央”服务器?
Thanks,
Ben
谢谢,
本
采纳答案by averell
Depends on what you mean by "server". Git will work happily without a central server, although many teams find it convenient to have a central repository.
取决于您所说的“服务器”是什么意思。Git 可以在没有中央服务器的情况下愉快地工作,尽管许多团队发现拥有中央存储库很方便。
If by "server", you mean "install server software", git will also work (central repository or not) without any special software, through ssh or on the file system.
如果“服务器”是指“安装服务器软件”,则 git 也可以在没有任何特殊软件的情况下通过 ssh 或在文件系统上工作(中央存储库与否)。
See this document for possible workflows
Workflow with common repository
具有公共存储库的工作流
The workflow that many use is that all developers "push" (send) their changes to a common repository, and get all the changes from that repository. Something like this:
许多人使用的工作流程是所有开发人员将他们的更改“推送”(发送)到一个公共存储库,并从该存储库中获取所有更改。像这样的东西:
- Developer A pushes to central
- Developer B pushes to central
- Developer C pulls (getting changes from A and B)
- Developer A pulls (getting changes from B)
- ...
- 开发者 A 推到中央
- 开发者 B 推到中央
- 开发人员 C 拉取(从 A 和 B 获取更改)
- 开发人员 A 拉取(从 B 获取更改)
- ...
In this case the central repository can be on one of the Developers computers, on github, or any other place
在这种情况下,中央存储库可以位于其中一台 Developers 计算机、github 或任何其他地方
Workflow with Email
电子邮件工作流程
You can also use git without any server, just using email. In this case the flow would be like this:
您也可以在没有任何服务器的情况下使用 git,只需使用电子邮件即可。在这种情况下,流程将是这样的:
- Developer A sends changes as an email to the team
- Other developers apply the changes from the emails
- 开发人员 A 将更改作为电子邮件发送给团队
- 其他开发人员应用电子邮件中的更改
This can even be done in a semi-automated way
这甚至可以以半自动化的方式完成
Workflow without a central server
没有中央服务器的工作流程
You can setup git to use more than one "remote" repository. The caveat is that you should neverpush to a repository that is checked out (that is, a Developer copy on which someone is working). So in this case the flow would be like this:
您可以设置 git 以使用多个“远程”存储库。需要注意的是,您永远不应推送到已检出的存储库(即某人正在使用的开发人员副本)。所以在这种情况下,流程是这样的:
- Developer A makes changes
- Developer B makes changes
- Developer C pulls changes from A
- Developer C pulls changes from B
- Developer B pulls changes from A
- ...
- No one must ever push
- 开发人员 A 进行更改
- 开发人员 B 进行更改
- 开发人员 C 从 A 中提取更改
- 开发人员 C 从 B 拉取更改
- 开发人员 B 从 A 中提取更改
- ...
- 没有人必须推动
IMHO this type of workflow will quickly lead to confusion and breakdown.
恕我直言,这种类型的工作流程会很快导致混乱和崩溃。
回答by ralphtheninja
What you need to do first, is to think through what kind of workflow you have already and configure git to work with that. Once you have something up and running, you can fine tune it. There is no need to setup a separate computer as a server. If you are accustomed to have a central repository all you need to do is to create a bare repository that everyone pushes to. Why not on the local network?
您首先需要做的是考虑您已经拥有什么样的工作流程,然后配置 git 来使用它。一旦您启动并运行了某些东西,您就可以对其进行微调。无需设置单独的计算机作为服务器。如果您习惯于拥有一个中央存储库,那么您需要做的就是创建一个每个人都推送到的裸存储库。为什么不在本地网络上?
Central repo:
中央回购:
mkdir foo.git
cd foo.git
git init --bare
Your repo:
你的回购:
mkdir foo
cd foo
git init
// add files
git add .
git commit -m "Initial commit"
git remote add origin //path/to/central/repo/foo.git
git push origin master
Other repos:
其他回购:
git clone //path/to/central/repo/foo.git
Now anyone can push and pull directly from master branch. This should be enough to get you started.
现在任何人都可以直接从 master 分支推拉。这应该足以让您入门。
回答by Andrew Aylett
You don't necessarily need to put a copy on a physical server somewhere, but it may help to have a 'blessed' repository somewhere -- make one of your team (possibly on a rotation) responsible for collecting and managing people's changes when they are ready to be treated as final. They can either keep a branch in their usual repository or maintain a separate repository on their local system to store the master sources.
您不一定需要将副本放在物理服务器上的某处,但在某处拥有一个“受祝福的”存储库可能会有所帮助 - 让您的团队中的一个(可能轮换)负责收集和管理人们的更改准备好被视为最终的。他们可以在他们常用的存储库中保留一个分支,也可以在本地系统上维护一个单独的存储库来存储主源。
As a concrete example, consider Linux and Linus Torvalds -- there's no central repository that everyone pushes to, but Linus maintains a repository which contains all of the code he considers 'ready' (and so do several other people, for different definitions of 'ready'). That way you've got a canonical definition of what code is in, and a place to define what your releases are.
作为一个具体的例子,考虑 Linux 和 Linus Torvalds —— 没有每个人都推送到的中央存储库,但 Linus 维护着一个存储库,其中包含他认为“就绪”的所有代码(其他几个人也是如此,对于 ' 的不同定义)准备好')。这样你就有了代码所在的规范定义,以及定义你的版本是什么的地方。
回答by Christoffer Hammarstr?m
You should setup a central server as a social construct, not a technical one, so that everyone knows where to find the latest official version, without any possibility for confusion.
您应该将中央服务器设置为一种社交结构,而不是技术结构,以便每个人都知道在哪里可以找到最新的官方版本,而不会造成任何混淆。
回答by Cormac Mulhall
As has been mentioned Git works really well without a centralised server. But a good reason to have a central server is to have an "always on" place to push code once a feature is completed that other developers can pull from without having to have access to your local machine.
如前所述,Git 在没有中央服务器的情况下运行得非常好。但是拥有一个中央服务器的一个很好的理由是有一个“永远在线”的地方来在一个功能完成后推送代码,其他开发人员可以从中提取而无需访问您的本地机器。
For example, currently I work on a 3 man dev team. We all work on laptops. We could have a work flow where we just pull from each other's machines. But if I work on a feature and commit my chances after everyone has left the office and I want them to take a look with this system they can't do anything unless my laptop is on and available on the network. If the guys turn up earlier than me (which they always do) they have to wait until my laptop is back online.
例如,目前我在一个 3 人开发团队工作。我们都在笔记本电脑上工作。我们可以有一个工作流程,我们只是从彼此的机器中提取。但是,如果我开发一个功能并在每个人都离开办公室后提交我的机会,并且我希望他们使用这个系统查看一下,除非我的笔记本电脑打开并且可以在网络上使用,否则他们将无能为力。如果这些人比我早到(他们总是这样做),他们必须等到我的笔记本电脑重新上线。
If I push to something like BitBucket or GitHub or just an always on server in the office, any of the other developers can simply pull the changes I've made when ever they are next online.
如果我推送到 BitBucket 或 GitHub 之类的东西,或者只是办公室里一个永远在线的服务器,任何其他开发人员都可以在他们下次上线时简单地提取我所做的更改。
That to me is the main reason to have a central server, and really it isn't a fault with Git but rather a consequence of working with laptops.
这对我来说是拥有中央服务器的主要原因,实际上这不是 Git 的问题,而是使用笔记本电脑的结果。
回答by Fredrik Pihl
Have a look at the Git for beginners: The definitive practical guide
section "How do you set up a shared team repository?"
“您如何设置共享团队存储库?”部分
回答by Jonathan del Strother
Git works pretty well with this sort of setup, although you'll want to avoid pushing changes to someone else's checked out branch ( https://git.wiki.kernel.org/index.php/GitFaq#Why_won.27t_I_see_changes_in_the_remote_repo_after_.22git_push.22.3F). You might have an integration branch that you push code to, and merge other people's changes from.
Git 在这种设置中工作得很好,尽管您希望避免将更改推送到其他人的已检出分支 ( https://git.wiki.kernel.org/index.php/GitFaq#Why_won.27t_I_see_changes_in_the_remote_repo_after_.22git_push。 22.3F)。您可能有一个集成分支,您可以将代码推送到该分支,并从中合并其他人的更改。
I think the main reason that a central repo is used a lot is that it can be taken as the canonical base for all your code, whereas it can be a little harder to reason about what you should be merging into when you have 3 or more branches of development going on.
我认为中央存储库被大量使用的主要原因是它可以作为所有代码的规范基础,而当你有 3 个或更多代码时,推理你应该合并的内容可能有点困难发展的分支正在进行中。