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:
![enter image description here](https://i.stack.imgur.com/9DX3H.png)
Suddenly, you realise that there is a bug on master
, a bug which you need to fix quickly. Instead of working directly off of master
, you should create a short-lived bug-fix branch, to isolate the bug-fixing task from your master
branch:
git checkout master
git checkout -b bugfix
![enter image description here](https://i.stack.imgur.com/HBSYC.png)
After making one commit (or more) on the bugfix
branch to fix the problem,
![enter image description here](https://i.stack.imgur.com/YgQQZ.png)
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
![enter image description here](https://i.stack.imgur.com/uc2JC.png)
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 basically have two options.
Merge master
into develop
, by running:
git checkout develop
git merge master
![enter image description here](https://i.stack.imgur.com/DDeud.png)
Alternatively, rebase develop
on top of master
, by running:
git checkout develop
git rebase master
![enter image description here](https://i.stack.imgur.com/u9yej.png)
In either case, your develop
branch will now contain the fix, and you can resume work on develop
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…