You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Git Flow管理发布版与develop分支时,如何追溯应用热修复?

Handling Urgent Develop Commits Needing Master Deployment in Git Flow

Great question! This is a common edge case when running Git Flow, and we can address it while staying true to your existing, well-running workflow’s core principles. Here’s a step-by-step breakdown that keeps everything consistent:

Step 1: Spin Up a Standard Hotfix Branch

Start by following Git Flow’s official hotfix initiation process to avoid breaking your workflow rhythm:

  • Check out your master branch and pull the latest production code:
    git checkout master
    git pull origin master
    
  • Create a descriptive hotfix branch (e.g., hotfix/urgent-production-fix):
    # Using the git-flow CLI tool
    git flow hotfix start urgent-production-fix
    
    # Manual branch creation if you don’t use the CLI
    git checkout -b hotfix/urgent-production-fix master
    

Step 2: Cherry-Pick the Critical Fix from Develop

First, grab the commit hash of the fix in your develop branch (use git log develop or your Git UI to find it—let’s say the hash is a1b2c3d):

  • Cherry-pick the commit into your new hotfix branch:
    git cherry-pick a1b2c3d
    
  • Critical: Resolve any merge conflicts that arise here. Since master might lag behind develop in non-fix code, conflicts are possible—take time to test the fix after resolving them to ensure it works in the production context.

Step 3: Validate the Fix Thoroughly

Before merging, run all relevant tests, do a local sanity check, or deploy the hotfix branch to a staging environment if possible. Even if the fix worked in develop, the production codebase might have subtle differences—don’t skip this step.

Step 4: Finalize the Hotfix (Merge to Master & Develop)

Wrap things up using standard Git Flow hotfix procedures to keep your branches aligned:

  • If using the git-flow CLI:

    git flow hotfix finish urgent-production-fix
    

    This command automatically:

    1. Merges the hotfix into master
    2. Creates a version tag for the hotfix (e.g., v1.2.1)
    3. Merges the hotfix back into develop
    4. Deletes the temporary hotfix branch
  • If doing it manually:

    1. Merge to master and tag the release:
      git checkout master
      git merge --no-ff hotfix/urgent-production-fix
      git tag -a vX.Y.Z -m "Hotfix: Urgent fix ported from develop"
      
    2. Merge back to develop (if the original commit is already in develop, Git might say "already up to date"—use git merge --ours to add the merge commit without changing code):
      git checkout develop
      git merge --no-ff hotfix/urgent-production-fix
      # Use this if you get an "already up to date" message:
      # git merge --ours hotfix/urgent-production-fix
      
    3. Delete the hotfix branch and push changes:
      git branch -d hotfix/urgent-production-fix
      git push origin master develop --tags
      

Key Tips to Avoid Headaches

  • Ensure the fix is self-contained: Make sure the cherry-picked commit doesn’t rely on other unmerged code in develop. If it does, you’ll need to cherry-pick those dependent commits too (or re-evaluate if a full release is necessary instead).
  • Communicate with your team: Let everyone know you’re porting a fix from develop to master to avoid merge conflicts or duplicate work.
  • Document the hotfix: Add a clear message to the tag or merge commit so future contributors understand why this fix was ported separately.

内容的提问来源于stack exchange,提问作者S.Richmond

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 11:04:28