主分支和开发分支之间的“git pull”或“git merge”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4556467/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:43:21  来源:igfitidea点击:

"git pull" or "git merge" between master and development branches

gitworkflow

提问by Carson

I have my masterbranch and a developbranch for working on a few changes. I need to merge changes from masterinto develop, but will eventually merge everything from developinto master. I have two different workflows in mind:

我有我的master分支和一个develop用于进行一些更改的分支。我需要将更改从masterinto合并develop,但最终会将所有内容从developinto合并master。我有两种不同的工作流程:

  1. git pull origin masterinto developbranch
  2. git merge masterinto developbranch
  1. git pull origin master进入develop分支
  2. git merge master进入develop分支

Which is the best way to do this, and why?

哪个是最好的方法,为什么?

采纳答案by Eric Leads

Be careful with rebase. If you're sharing your develop branch with anybody, rebase can make a mess of things. Rebase is good only for your own local branches.

使用 rebase 时要小心。如果您要与任何人共享您的开发分支,则 rebase 会使事情变得一团糟。Rebase 仅适用于您自己的本地分支机构。

Rule of thumb, if you've pushed the branch to origin, don't use rebase. Instead, use merge.

经验法则,如果您已将分支推送到原点,请不要使用变基。相反,使用合并。

回答by Ian Lotinsky

This workflow works best for me:

这个工作流程最适合我:

git checkout -b develop

...make some changes...

……做些改变……

...notice master has been updated...

...通知主已更新...

...commit changes to develop...

...提交更改以开发...

git checkout master
git pull

...bring those changes back into develop...

...将这些更改重新开发...

git checkout develop
git rebase master

...make some more changes...

……再做些改变……

...commit them to develop...

...承诺他们发展...

...merge them into master...

...将它们合并为 master ...

git checkout master
git pull
git merge develop

回答by divegeek

The best approach for this sort of thing is probably git rebase. It allows you to pull changes from master into your development branch, but leave all of your development work "on top of" (later in the commit log) the stuff from master. When your new work is complete, the merge back to master is then very straightforward.

这种事情的最佳方法可能是git rebase. 它允许您将更改从 master 拉入您的开发分支,但将您的所有开发工作“放在”(稍后在提交日志中)来自 master 的内容。当您的新工作完成后,合并回 master 就非常简单了。

回答by KiRPiCH

If you are not sharing develop branch with anybody, then I would just rebase it every time master updated, that way you will not have merge commits all over your history once you will merge develop back into master. Workflow in this case would be as follows:

如果您不与任何人共享开发分支,那么每次主更新时我都会重新设置它,这样一旦您将开发合并回主,您就不会在整个历史记录中进行合并提交。这种情况下的工作流程如下:

> git clone git://<remote_repo_path>/ <local_repo>
> cd <local_repo>
> git checkout -b develop
....do a lot of work on develop
....do all the commits
> git pull origin master
> git rebase master develop

Above steps will ensure that your develop branch will be always on top of the latest changes from the master branch. Once you are done with develop branch and it's rebased to the latest changes on master you can just merge it back:

以上步骤将确保您的开发分支始终位于主分支的最新更改之上。完成开发分支后,它会重新基于 master 上的最新更改,您可以将其合并回来:

> git checkout -b master
> git merge develop
> git branch -d develop

回答by hoijui

my rule of thumb is:

我的经验法则是:

rebasefor branches with the same name, mergeotherwise.

rebase对于具有相同名称的分支,merge否则。

examples for same names would be master, origin/masterand otherRemote/master.

相同名称的示例是master,origin/masterotherRemote/master

if developexists only in the local repository, and it is always based on a recent origin/mastercommit, you should call it master, and work there directly. it simplifies your life, and presents things as they actually are: you are directly developing on the masterbranch.

如果develop仅存在于本地存储库中,并且它始终基于最近的origin/master提交,则应调用它master,并直接在那里工作。它简化了您的生活,并按实际情况呈现事物:您直接在master分支上进行开发。

if developis shared, it should not be rebased on master, just merged back into it with --no-ff. you are developing on develop. masterand develophave different names, because we want them to be different things, and stay separate. do not make them same with rebase.

如果develop是共享的,则不应重新基于master,只需将其与--no-ff. 你正在开发developmasterdevelop有不同的名称,因为我们希望它们是不同的东西,并且保持独立。不要让它们与rebase.