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

Bitbucket中更新Pull Request的最优方案及无新提交更新方法

Updating Pull Requests in Bitbucket: Two Common Scenarios

Let me break this down for you based on Atlassian's official guidelines and common team practices in Bitbucket:

1. Best Way to Update a Pull Request in Bitbucket

According to Atlassian's recommendations, the standard and safest approach is to:

  • Switch to your PR branch locally: git checkout your-pr-branch
  • Make the necessary code changes based on reviewer feedback
  • Create a new commit with a clear message explaining the updates (e.g., git commit -m "Fix: Resolve input validation issue noted in review")
  • Push the new commit to your remote branch (either the original repo branch or your fork): git push origin your-pr-branch

Bitbucket will automatically sync this new commit to your existing PR. The benefit here is that you preserve a full audit trail—your original work stays intact, and each round of review changes is tracked as a separate commit. This makes it easy for reviewers to compare what's changed since their last look.

2. Best Way to Update a PR Without Creating New Commits (For a Single-Commit PR)

If your goal is to have one clean commit per PR (instead of tracking multiple review-related commits), you can rewrite your existing commit history to fold changes into the original commit. Important note: Only do this if you're the only person working on the branch—rewriting history can cause conflicts for other collaborators.

Here are two reliable methods:

Method 1: Amend the Original Commit

  • Switch to your PR branch and make your code changes
  • Stage the modified files: git add .
  • Merge the changes into your existing commit: git commit --amend
    • This will open your default text editor—you can keep the original commit message or update it to reflect the full set of changes, then save and exit
  • Push the updated commit to Bitbucket with a force push (use the safer --force-with-lease option to avoid overwriting unexpected changes): git push origin your-pr-branch --force-with-lease

Method 2: Interactive Rebase (For More Control)

If you need to adjust earlier commits or combine multiple small commits into one, use interactive rebase:

  • Run git rebase -i HEAD~1 (replace 1 with the number of recent commits you want to modify)
  • In the editor that opens, change the word pick to edit next to the commit you want to update
  • Save and exit the editor, then make your code changes
  • Stage the changes: git add .
  • Continue the rebase process: git rebase --continue (you can update the commit message here if needed)
  • Push the updated history to Bitbucket: git push origin your-pr-branch --force-with-lease

While Atlassian's default guidance favors keeping review changes as separate commits for transparency, this rewrite approach is widely accepted when teams prefer clean, single-commit PRs—just make sure to coordinate with your team first if others are working on the same branch.

内容的提问来源于stack exchange,提问作者user2738748

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:36:45