git 合并两个分支以创建新分支

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

Merge two branches to create new branch

gitversion-control

提问by Thomas Clayson

We have a few branches...

我们有几家分店...

  • masteris our dev branch.
  • feature-newfeatureis a new feature.
  • feature-tempfeatureis a new feature that our product team have asked for until new feature is created. feature-newfeaturewas started a while ago and hasn't been merged into masteryet (but there have been other changes to master).
  • master是我们的开发分支。
  • feature-newfeature是一个新功能。
  • feature-tempfeature是我们的产品团队在创建新功能之前要求的新功能。feature-newfeature是在不久前开始的,尚未合并到master(但对 进行了其他更改master)。

We have now been instructed to put this temp feature in which needs all the changes from master- so its a releasable build - but also needs some of the stuff we've been working on in newfeature(as they say "you can reuse some of the stuff you've already done").

我们现在被指示将这个临时功能放在其中需要所有更改master- 所以它是一个可发布的构建 - 但也需要我们一直在努力的一些东西newfeature(正如他们所说的“你可以重用一些东西你已经完成了”)。

How would it be best to go about doing this? I have created feature-tempfeaturefrom the masterbranch. feature-newfeatureisn't finished, and I don't want to merge it into master.

如何最好地去做这件事?我是feature-tempfeaturemaster分支创建的。feature-newfeature没有完成,我不想将其合并到master中。

I don't want to just use feature-newfeatureeither because we want to be able to keep working on that in parallel.

我不想只使用它们feature-newfeature,因为我们希望能够继续并行处理。

How would you sort out this issue in your dev environment?

你会如何在你的开发环境中解决这个问题?

Many thanks!

非常感谢!

回答by Max Leske

branches are just aliases for a specific commit. Therefore you can have multiple branches that actually point to the same commit. So, what you could do is to create a new branch newBranchthat points to the same commit as master and then merge feature-tempfeatureinto newBranch. The effect would be the same as merging into master, except that master stays untouched.

分支只是特定提交的别名。因此,您可以拥有多个实际指向同一个提交的分支。因此,您可以做的是创建一个新分支newBranch,该分支指向与 master 相同的提交,然后合并feature-tempfeaturenewBranch. 效果与合并到 master 相同,只是 master 保持不变。

回答by uday

From my understanding your scenario is:

根据我的理解,您的情况是:

---master----
\___tempf____
\___newf_____

Your problem:You need tempfwith changes of masteras well as newfso

你的问题:你需要tempf使用的变化master,以及newf因此

Solution:

解决方案:

1) Stash your unsaved changes in tempfwith $ git stash

1)在藏你未保存的更改tempf$ git stash

2) Merge master with tempf and merge newf with tempf to have the changes of the both master and newf

2) 将master与tempf合并,将newf与tempf合并,得到master和newf的变化

3) Stash pop your changes with $ git stash pop

3) Stash pop 你的改动 $ git stash pop

And as @MaxLeske said, branches are just aliases, they serve just like pointer to a commit but are not the commits themselves.

正如@MaxLeske 所说,分支只是别名,它们就像指向提交的指针一样,但不是提交本身。