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

如何将含未签名提交的dev分支合并至master分支?

Got it, let's tackle this problem step by step. The core issue here is that your dev branch has unsigned commits, and now you need all commits to be signed before merging into master. There are two solid approaches depending on whether you're working alone on dev or collaborating with others—let's walk through both:

前提准备:确保你的GPG签名配置正确

First things first, make sure Git is set up to sign your commits. If you haven't done this yet:

  • Check if you've already configured a signing key:
    git config --global user.signingkey
    
    If nothing outputs, you'll need to set your GPG key ID here (replace <your-gpg-key-id> with your actual key ID):
    git config --global user.signingkey <your-gpg-key-id>
    
  • Optional but recommended: Turn on automatic commit signing so you don't have to add -S every time:
    git config --global commit.gpgsign true
    

方案一:重签所有历史提交(适合单人维护的dev分支)

If you're the only one working on dev and don't mind rewriting commit history (this will change the commit hashes, so avoid this if others have pulled the branch), follow these steps:

  1. Switch to your dev branch:
    git checkout dev
    
  2. Identify the first unsigned commit. You can list all commits with their signature status using:
    git log --show-signature
    
    Look for commits that don't have a gpg: Good signature from... line.
  3. Start an interactive rebase to edit all commits from that first unsigned one onward. Replace <first-unsigned-commit-hash> with the hash of that first unsigned commit:
    git rebase -i <first-unsigned-commit-hash>^
    
    (The ^ at the end tells Git to include that commit in the rebase.)
    If every commit on dev is unsigned, use git rebase -i --root instead to edit all commits from the start.
  4. In the text editor that pops up, change every pick to edit (or just e for short) next to the commits you need to re-sign. Save and close the editor.
  5. Git will pause at each commit one by one. For each paused commit, run:
    git commit --amend --no-edit -S
    
    The --no-edit keeps the original commit message, and -S signs it. Then continue the rebase:
    git rebase --continue
    
    Repeat this until all commits are re-signed.
  6. Push the updated dev branch to remote. Since you rewrote history, you'll need to force push—use --force-with-lease instead of plain --force to avoid accidentally overwriting others' work (even if you're alone, it's safer):
    git push origin dev --force-with-lease
    
  7. Now you can merge dev into master normally. If you didn't enable automatic signing, add -S to the merge commit:
    git checkout master
    git merge -S dev
    

方案二:创建一个新的签名提交(适合多人协作的dev分支)

If others are working on dev and rewriting history would cause conflicts, this approach keeps the original commits intact but creates a single signed commit with all the changes:

  1. Switch to master and create a new temporary branch:
    git checkout master
    git checkout -b dev-signed
    
  2. Squash all changes from dev into this new branch. This will stage all the changes from dev without creating individual commits:
    git merge --squash dev
    
  3. Create a signed commit with all the squashed changes. Write a clear message explaining this is the consolidated signed version of dev:
    git commit -S -m "Squashed and signed all changes from dev branch"
    
  4. Now merge this signed branch into master:
    git checkout master
    git merge dev-signed
    
  5. Clean up the temporary branch (optional):
    git branch -d dev-signed
    

验证所有提交已签名

After either approach, double-check that all relevant commits are signed with:

git log --show-signature

Look for the gpg: Good signature from... line next to each commit to confirm they're properly signed.

内容的提问来源于stack exchange,提问作者J. Ordaz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:46:10