How can I do a bugfix on master and integrate it into my less stable branch(es)?

二次信任 提交于 2019-11-28 00:14:40

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.

let's suppose you have you master and dev branches.

You work on dev for your new features and you do your fix on master.

Then you checkout dev and merge master into dev. This way master is fixed and dev can profit from the fix you made AND keeps it's own history.

Alternatively, you can rebase dev on top of branch. This gives you a "cleaner" history in the sense that you don't have merge points.

See the git guide about merging: http://git-scm.com/docs/git-merge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!