Git和在多个分支上工作 [英] Git and working on multiple branches

查看:119
本文介绍了Git和在多个分支上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个Git分支:'实验','东西'和'主'。

我切换到'实验'分支。我注意到一个与'实验'无关的错误,属于'某事'中所做的改变。我应该如何解决它?



我想我应该切换到'某些',修正错误,提交然后回到'实验'。我应该如何从'某事'中做出微小的改变,并将它应用于'主'和'实验',以便在切换到这些分支时不必重新修复错误?

解决方案

您可以使用以下两种解决方案:使用主题分支或使用樱桃采摘






主题分支解决方案



主题分支解决方案,您切换到分支'something',创建分支以修复错误,例如'something-bugfix',将这个分支合并成'something'(修正这个bug),然后把这个分支合并到'experimental'中。

  $ git checkout -b东西修正东西

$ git结帐东西
$ git合并东西 - 修复
$ git结帐实验
$ git merge something-fix
[修复冲突如果需要并提交]

另请参阅< a href =http://gitster.livejournal.com/27297.html =noreferrer>解决主题分支早期的冲突/依赖和永不合并,也许还会承诺一个不同的分支 Junio C Hamano(git维护者)的博客文章。




樱桃挑选bug修复



如果您稍后注意到 ,那么樱桃采摘解决方案很有用您创建的错误修正(例如在开发分支上)对其他分支(例如稳定分支)也是有用的。在你的情况下,你会修改'something'分支:

  $ git checkout something 
[edit,edit ,编辑]
$ git commit
$ git checkout experimental

然后你注意到了确定你参与某事的分支也应该放在'实验'分支上。假设这个错误修正是提交'A'(例如'something',如果你没有在'something'之上提交任何东西,但可能是'something〜2'或'c84fb911'):

  $ git checkout experimental 
$ git cherry-pick A

(您可以使用 - 编辑选项 git cherry-pick if你想在编辑提交消息之前编辑挑选的bug修复程序)。


I have a couple of Git branches: 'experimental', 'something' and 'master'.

I switched to the 'experimental' branch. I noticed a bug which is unrelated to 'experimental' and belongs to changes which have been made in 'something'. How should I fix it?

I'm thinking I should switch to 'something', fix the bug, commit and then move back to 'experimental'. How should I take the minor change from 'something' and apply it to both 'master' and 'experimental' so that I don't have to re-fix the bug again when I switch into these branches?

解决方案

There are two solutions not mentioned already that you can use: use a topic branch or use cherry-picking.


Topic branch solution

In the topic branch solution, you switch to branch 'something', create a branch to fix a bug e.g. 'something-bugfix', merge this branch into 'something' (fixing the bug), then merge this branch into 'experimental'.

$ git checkout -b something-fix something
[edit, commit]
$ git checkout something
$ git merge something-fix
$ git checkout experimental
$ git merge something-fix
[fix conflicts if necessary and commit]

See also Resolving conflicts/dependencies between topic branches early and Never merging back, and perhaps also Committing to a different branch blog posts by Junio C Hamano (git maintainer).


Cherry-picking a bugfix

The cherry-picking solution is useful if you noticed later that the bugfix you created (e.g. on development branch) would be useful also on other branch (e.g. stable branch). In your case you would comit a fix on 'something' branch:

$ git checkout something
[edit, edit, edit]
$ git commit
$ git checkout experimental

Then you noticed that fix you comitted in 'something' branch should be also on 'experimenta' branch. Lets say that this bugfix was commit 'A' (e.g. 'something' if you didn't commit anything on top of 'something', but it might be e.g. 'something~2' or 'c84fb911'):

$ git checkout experimental
$ git cherry-pick A

(you can use --edit option to git cherry-pick if you want to edit commit message before comitting cherry-picked bugfix).

这篇关于Git和在多个分支上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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