分支溢出?

时间:2016-09-16 03:32:19

标签: git github

这里有点困惑。当您创建新分支时,是否立即发布它,进行更改然后合并它或者您是否在本地工作然后将其合并到本地主服务器然后将本地主服务器推送到远程主服务器?

它们是一样的吗?你能告诉我这些步骤吗?

2 个答案:

答案 0 :(得分:1)

这取决于很多因素:

  1. 您是独自工作还是与某个分支机构中的某个人一起工作?如果您与某人合作,则需要同步更改,因此您需要将其推送到远程分支。

  2. 您是使用不同的电脑/笔记本电脑吗?如果是,使用git很容易同步更改。此外,如果您害怕丢失更改并且想要确定,请将它们推送到远程分支。

  3. 等...

    一般来说,我宁愿推动改变,即使我独自工作到远程分支,以确保我不会丢失它们。如果我想在远程分支中进行更改,有时我也可以使用--force推送。

答案 1 :(得分:1)

git的主要好处是它是分布式源代码管理。您可以在工作站上查看源代码历史记录的完整视图。

因此,当您创建分支时,您希望在本地提交一次或多次。

您是否合并到特定分支取决于您和您的项目。通常,项目会成为一个开发分支并从中解决问题,让主要项目负责人进行合并。您可以直接将本地分支合并到远程分支,许多项目都希望您以这种方式工作。 Git helps you with tools to setup your remote tracking relationship.

事实上,github已经在流程中设计了一个审查系统,为开源项目的用户提供工具,他们希望对合并进行精细控制,而无需人们直接访问共享远程存储库。 This is explained in illustrated fashion here

然而,最简单的说法是,这里有一个git流程,可以与任何远程源一起使用,在那里你有权将上游推回到远程:

git clone some-project
# you are on the master branch
cd some-project
git checkout -b new-topic
# you are in your new-topic branch
# add a file
touch a-new-file.txt
git add a-new-file-txt
git commit -m "Added a-new-file.txt"
git checkout master
# let's see if anything new was pushed to the remote
git pull
# now merge new-topic into master
git merge new-topic
# If there are no merge conflicts, you have a new master to smoke test
# All seems well?  (unit tests were run and passed, you did some testing?)
git push
# Lather, rinse, repeat.

本例中的假设(或默认)伴随着拉动和推动。由于我每次都推送master,所以真正发生的事情是我的本地主分支正在跟踪我的遥控器的“origin master”分支。假设主要开发人员想要查看您的代码,并告诉您将分支推送到远程。你会怎么做?

git clone some-project
# you are on the master branch
cd some-project
git checkout -b new-topic
# you are in your new-topic branch
# add a file
touch a-new-file.txt
git add a-new-file-txt
git commit -m "Added a-new-file.txt"
git push -u origin new-topic
# Now people can pull your branch from the remote

请注意,github是一个不同的野兽,即使它是git,也可以处理拉取请求。