我如何在master上进行bug修复并将其集成到我的不太稳定的分支中? [英] How can I do a bugfix on master and integrate it into my less stable branch(es)?

查看:355
本文介绍了我如何在master上进行bug修复并将其集成到我的不太稳定的分支中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



然而,因为我是唯一一个在我的项目上工作的人,我一直使用的唯一命令是

  git status 
git add。
git commit -m'message here'
git push origin master

I已经很久以前把这个项目推到了遥远的地方(我部署了Capistrano),并且所有的工作都非常棒。

现在我想改变网站的设计,但保持逻辑完整。我想我需要创建一个新的分支(让我们称之为 newdesign )。



但是,想知道的是,如果我正在处理 newdesign 分支,并且在 master 中看到一个错误$ c> branch,我该如何修正 master 上的错误,然后将错误修复集成到 newdesign 分支中,所以后者应该与实际的逻辑保持一致?

解决方案

这是一个经典案例,您可以利用Git分支。这是您应该使用的工作流程。



假设您创建了开发分支,源于 master ,并且您已经在该分支上进行了一些提交:


突然间,你意识到你需要快速修复
;而不是直接从 master 工作,您应该创建一个短暂的错误修复分支,从您的 master 分支:

  git checkout master 
git checkout -b bug修正



bugfix 分支上进行一次提交(或更多)以解决问题后,





你应该确保一切正常(运行测试等)。当你对 bugfix 的代码状态感到满意时,将它合并到 master 中:

  git checkout master 
git合并bugfix



在这个阶段,你可以将你的(现在已经修复的) master 分支推送到远程,并且删除 bugfix 分支:

  git push origin master 
git branch -d bugfix

现在,将 master 的最新更改集成到 develop ,你基本上有两个选择。


  1. 合并 master

      git checkout开发$ b将c>转换为 develop  $ b git merge master 

  2. 另外,rebase 开发 master 之上,通过运行:

      git checkout develop 
    git rebase master


无论哪种情况,您的 develop 分支现在都会包含bug修复,您可以继续使用它。


I'm using Git for one of my projects at the moment, and I love it.

However, because I'm the only one working on my project, the only commands I've been using are

git status
git add .
git commit -m 'message here'
git push origin master

I have pushed the project to remote a long time ago ago (I Capistrano for deployment), and all is working great.

Now I want to change the design of the site, but keep the logic intact. I'm guessing I need to create a new branch (let's call it newdesign) for that.

What I'm wondering, though, is this: if I'm working on the newdesign branch, and I see a bug in the master branch, how can I fix the bug on master and then integrate that bugfix in the newdesign branch, so that the latter be kept up to date with the actual logic?

解决方案

This is a classic case in which you can take advantage of Git branches. Here is the workflow you should use.

Let's say you've created a develop branch stemming from master and you've made a few commits on that branch:

Suddenly, you realise you need to quickly fix a bug on master; instead of working directly off of master, you should create a short-lived bugfix branch, to isolate the bug-fixing task from your master branch:

git checkout master
git checkout -b bugfix

After making one commit (or more) on the bugfix branch to fix the problem,

you should make sure that everything works as it should (run tests, etc.). When you're happy with the state of your code on bugfix, merge it into master:

git checkout master
git merge bugfix

At that stage, you can push your (now fixed) master branch to remote, and delete the bugfix branch:

git push origin master
git branch -d bugfix

Now, to integrate the latest changes on master into develop, you essentially have two options.

  1. Merge master into develop, by running:

    git checkout develop
    git merge master
    

  2. Alternatively, rebase develop on top of master, by running:

    git checkout develop
    git rebase master
    

In either case, your develop branch will now contain the bugfix, and you can resume work on it.

这篇关于我如何在master上进行bug修复并将其集成到我的不太稳定的分支中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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