简体   繁体   English

分支中的错误修复

[英]Bug fixes in branch

I'm a sole developer with one main development branch, and one or more feature branches. 我是拥有一个主要开发分支和一个或多个功能分支的唯一开发人员。

I'm wondering right now, if I'm actively developing in a feature branch and I discover a bug in the main branch, what would be the best practice. 我现在想知道,如果我正在功能分支中积极开发并且发现主分支中的错误,那是最佳实践。 I would assume: 我会假设:

  1. I switch back to main dev branch, fix bug, commit. 我切换回主要开发分支,修复错误,提交。
  2. Switch to feature branch, and merge main branch to feature branch. 切换到要素分支,然后将主分支合并到要素分支。
  3. Continue developing on feature branch. 继续在功能分支上进行开发。

The above seems to be very cumbersome, all the while losing my current place in the feature branch and breaking my train of thought. 上面的内容似乎非常繁琐,同时始终失去了我在功能分支中的位置并打破了我的思路。 Is there a better method? 有没有更好的方法?

Assuming that you deploy to production from your master branch and that feature branches are merged back into master once done I would: 假设您从master分支部署到生产环境,并且功能分支一旦完成合并到master中,我将:

Commit whatever work is done on the feature branch, regardless of it builds or not 提交在功能分支上完成的所有工作,无论是否构建

git commit -a -m'saving work to fix bug'

Checkout the master branch and fix the bug and commit it 检出master分支并修复错误并提交

git checkout master
code some
git commit -a -m'fixed nasty production bug'

Then checkout the feature branch, rebase the changes and continue work 然后签出功能分支,重新设置更改基础并继续工作

git checkout feature
git rebase
git reset --soft HEAD^

That last command will move HEAD one commit back but leave all code in the working copy intact, making it possible to resume work on the feature branch. 最后一条命令会将HEAD移回一次提交,但完整保留工作副本中的所有代码,从而可以继续执行功能分支上的工作。 Note that depending on what was fixed on master you might get conflicts when rebasing. 请注意,根据主机上的固定内容,重新设置基准时可能会发生冲突。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM