Git分支用于开发dev,同时将一些更改合并到master中 [英] Git branches for working on dev while merging some changes into the master

查看:1016
本文介绍了Git分支用于开发dev,同时将一些更改合并到master中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,使用SVN,我会有一个分支,它是我的开发分支,它与开发网站上的代码相匹配。偶尔,我会在开发分支中进行更改,然后将更改合并到主干中,以便将其投入生产。我想知道我可能会用git做类似的事情。

Previously, using SVN, I would have a branch that was my development branch, which matched the code on the development site. Once in a while, I would make a change in the development branch and then merge just the change into the trunk so I could put it on production. I'm wondering how I might accomplish something similar with git.

基本上,我希望能够合并1个或几个来自分支的提交,而不合并整个分支。

Basically, I want to be able merge 1 or a few commits from the branch into the master without merging the entire branch.

或者我应该以不同的方式使用git? (我需要立即发布变更,所以我无法完成所有更改。)我应该使用多个分支吗?我可以合并1分支到多个其他分支吗?

Or should I be working with git differently? (I need to release the changes right away so I can't way till all the changes are done.) Should I be working with multiple branches? Can I merge 1 branch into multiple other branches?

推荐答案

你几乎可以回答你的问题:是的,你可以合并一个分支到多个其他分支。

You've almost answered your question: yes, you can merge one branch into multiple other branches.

所以,你想要做的是创建一个分支只是为了这个功能/错误修正(通用名是主题),从一个您想要合并到的所有分支的共同祖先。做你的工作,提交它,然后将它合并到所有这些。

So, what you want to do is create a branch just for this feature/bugfix (the common name is "topic"), starting from a common ancestor of all branches you'll want to merge it into. Do your work, commit it, then merge it into all of those.

# say version 1.2.3 is a common ancestor, and it's tagged
git checkout -b bugfix v1.2.3

# do some stuff
git add ...
git commit

git checkout master
git merge bugfix

git checkout dev
git merge bugfix
...

这里的关键部分是确保在共同的祖先开始分支。如果你不这样做,你最终也会合并其他东西。

The key part here is to make sure to start your branch at a common ancestor. If you don't, you'll end up merging pieces of other things in as well.

如果由于某种原因很难找到一个好的共同祖先,你可以回到樱桃采摘。这实质上是将提交从一个地方复制到另一个地方。尽管如此,最好尽量避免它,因为它确实意味着最终会有两次历史记录提交。

If for some reason it's difficult to find a good common ancestor, you can fall back to cherry-picking. This essentially copies a commit from one place to another. It's best to avoid it when you can, though, since it does mean you end up with two copies of a commit in the history.

这篇关于Git分支用于开发dev,同时将一些更改合并到master中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆