22

我只将 Git 用于单个项目。现在我想继续和另外两个开发者一起做一个项目。

如果一个开发人员想要提交更改但另一个开发人员创建了另一个提交,它会导致问题吗?因此,为我们每个人创建一个分支是否有意义?

4

2 回答 2

36

与大多数版本控制系统一样,Git 非常适合多个开发人员使用。事实上,它是版本控制系统的要点之一。

无需为每个用户创建一个分支。我什至会说这会适得其反。如果您正在开发相同的功能,您可能希望通过拉取和合并来获取彼此的更改。为每个用户创建分支是多余的,并且会使事情变得不必要地复杂化。

您描述的提交情况没有问题。如果另一个用户在与您相同的分支上创建了新提交,如果您尝试push. 相反,您首先必须pull关闭其他用户的提交并将您的工作与这些更改合并(或变基)。这是 的标准行为git pull

通常的做法是主要基于特征创建分支。如果您需要有关分支的指导,这是一种流行的策略

于 2013-06-25T17:27:00.493 回答
7

We used to do that in a place where I worked. Each of us had at least one personal branch - I actually created a branch for every task I had to do.

When we were done, we would do pull requests to the main branch. If someone has merged into the main branch code that conflicts with your changes, you have to do the conflict resolution just as you would with any other source control platform (like Tortoise, Mercurial etc.), but it's no big deal if your devs know what they're doing.

IMO this is the best way to conduct development in a team. You can always test in your own personal environment, quickly swicthing code from each branch as needed. The pull request system also makes peer review so much simpler, since everybody can collaborate and write comments on the relevant lines directly in the github diff pages.

于 2013-06-25T17:29:18.067 回答