GitFlow流程中发布版合并至master/develop后,生产Bug修复方案咨询
Great question—this is a tricky edge case in GitFlow, but there’s a clear, team-friendly way to resolve it without mangling your branch history. Here’s your step-by-step playbook:
1. Roll back master and develop to the pre-release stable state
You already merged release/1.1 into both branches, but since the 1.1 launch is delayed, you need to get your branches back in sync with the current live production version (let’s assume that’s 1.0).
If you haven’t pushed the merges to remote yet:
- Check out
masterand reset it to the last stable commit (use the 1.0 release tag or its commit hash):git checkout master git reset --hard <commit-hash-of-1.0-release> - Repeat the same reset for
develop:git checkout develop git reset --hard <commit-hash-of-1.0-release> - Pro tip: Run
git log --onelineto quickly find the right commit hash.
- Check out
If you already pushed the merges to remote:
Hard resetting rewrites public history (bad news for your team), so usegit revertinstead to create a new commit that undoes the merge:- Find the hash of the merge commit (look for lines like
Merge branch 'release/1.1'ingit log):git checkout master git revert -m 1 <merge-commit-hash> git push origin master - Do the same revert for
develop:git checkout develop git revert -m 1 <merge-commit-hash> git push origin develop
- Find the hash of the merge commit (look for lines like
2. Create a hotfix branch for the production bug
Since the issue is in your live 1.0 environment, use GitFlow’s hotfix workflow to target it directly:
- Check out the now-stable
masterbranch:git checkout master - Spin up a hotfix branch (name it to reflect the patch version, e.g.,
hotfix/1.0.1):git checkout -b hotfix/1.0.1
3. Fix the bug and merge the hotfix
- Implement your bug fixes on the
hotfix/1.0.1branch, commit with clear messages, and test thoroughly. - Once the fix is validated, merge it back to
masterand tag the new production patch:git checkout master git merge hotfix/1.0.1 git tag -a 1.0.1 -m "Hotfix: Resolve production instability" git push origin master --tags - Merge the hotfix into
developtoo—this ensures when you restart the 1.1 release later, the fix is included:git checkout develop git merge hotfix/1.0.1 git push origin develop
4. Clean up and restart the 1.1 release
- Delete the hotfix branch (local and remote if you pushed it):
git branch -d hotfix/1.0.1 git push origin --delete hotfix/1.0.1 - When production stabilizes and you’re ready to resume the 1.1 launch, follow standard GitFlow: create a new
release/1.1branch fromdevelop, run final tests, merge tomasteranddevelop, tag 1.1, and delete the release branch.
内容的提问来源于stack exchange,提问作者NicolasW

