git - 如何修复 GitHub pull 请求中被 git rebase 破坏的提交顺序?

标签 git github rebase

当我编写代码时,我会将其分解成小的逻辑更改,以便于快速审查。

为此,我使用 git rebase -i(交互式)来压缩、删除和更改提交的顺序。

我注意到这有时会导致 GitHub pull 请求的提交顺序不同(尽管该顺序保留在远程分支上)。

例如,

  • 提交 1
  • 提交 2
  • 提交 3

可能在 PR 中显示为:

  • 提交 3
  • 提交 1
  • 提交 2

我搜索了互联网,只找到了这个 GitHub 帮助页面:Why are my commits in the wrong order?他们的回答:

If you rewrite your commit history via git rebase or a force push, you may notice that your commit sequence is out of order when opening a pull request.

GitHub emphasizes Pull Requests as a space for discussion. All aspects of it--comments, references, and commits--are represented in a chronological order. Rewriting your Git commit history while performing rebases alters the space-time continuum, which means that commits may not be represented the way you expect them to in the GitHub interface.

If you always want to see commits in order, we recommend not using git rebase. However, rest assured that nothing is broken when you see things outside of a chronological order!

有没有办法解决这个问题?

最佳答案

我已经通过以下方式解决了这个问题:

  1. 找到保留顺序的最后一次提交
  2. 运行 git rebase -i <hash of that commit>
  3. 全部替换pickreword
  4. 运行 git push -f

在此之前,我尝试仅更改第一个提交消息,这也更改了以下所有哈希值,但这并没有解决问题。

我也必须为每个后续提交执行此操作才能使其正常工作。

关于git - 如何修复 GitHub pull 请求中被 git rebase 破坏的提交顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44704519/

相关文章:

git - git 功能、发布和修补程序之间有什么区别?

asp.net - Windows 版咕噜维基?

git rebase,跟踪 'local' 和 'remote'

git - 如何管理 Git "upstream"分支和相关补丁?

git - 使用 bitbucket 管道部署到 heroku 到非 master 分支

git - 如何将分支上的修补程序 merge 到 master

你喜欢/离不开的 Git 命令

git - 如何将 git 中的子模块更新为该外部仓库中的 HEAD 提交

git - 获取多个非连续提交的累积 git 差异

git - 如何对大量提交进行 rebase