如何修复被 git rebase 破坏的 GitHub 拉取请求中的提交顺序? [英] How to fix commit order in GitHub pull requests, broken by git rebase?

查看:40
本文介绍了如何修复被 git rebase 破坏的 GitHub 拉取请求中的提交顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我编写代码时,我会将其分解为易于审查的小逻辑更改.

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

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

例如

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

可能会在 PR 中显示为:

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

我在互联网上搜索并只找到了这个 GitHub 帮助页面:为什么我的提交顺序错误? 他们的回答:

<块引用>

如果你通过 git rebase 或强制推送重写你的提交历史,你可能会注意到您的提交顺序在打开一个拉取请求.

GitHub 强调 Pull Requests 作为讨论空间.各方面它——评论、引用和提交——被表示在一个时间顺序.重写你的 Git 提交历史 while执行 rebases 会改变时空连续体,这意味着提交可能不会以您期望的方式表示GitHub 接口.

如果你总是想按顺序查看提交,我们建议不要使用git rebase.但是,请放心,当您不按时间顺序看东西!

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

解决方案

您可能不再需要修复任何问题(2020 年 7 月,3 年后)

见:

<块引用>

拉取请求提交现在按时间顺序排列

<块引用>

我们正在更改拉取请求时间线和提交视图中提交的排序方式.

提交当前按作者日期排序,这可能会导致提交在某些情况下出现乱序,例如在重新设定基准之后.

此更改后,提交将根据其在 head 分支中的时间顺序进行排序,这与 Git 中的顺序一致.

此排序也反映在 列出拉取请求的提交 REST API 和PullRequest GraphQL 中对象的时间线连接.

详细了解拉取请求

When I write code I break it into small logical changes that are easy and quick to review.

To do so, I use git rebase -i (interactive) to squash, drop and change order of commits.

I've noticed this sometimes leads to a different order of commits on a GitHub pull request (though the order is retained on the remote branch).

For example,

  • commit 1
  • commit 2
  • commit 3

might show up in the PR as:

  • commit 3
  • commit 1
  • commit 2

I've searched the internet and only managed to find this GitHub help page: Why are my commits in the wrong order? Their answer:

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!

Is there a way to work around this?

解决方案

You might not have to fix anything anymore (July 2020, 3 years later)

See:

Pull request commits now ordered chronologically

We are changing the way commits are ordered in the pull request timeline and commits view.

Commits are currently ordered by author date, which can cause commits to appear out of order in some scenarios, like after rebasing.

With this change, commits are ordered according to their chronological order in the head branch, which is consistent with the ordering in Git.

This ordering is also reflected in the List commits on a pull request REST API and PullRequest object's timeline connection in GraphQL.

Learn more about pull requests

这篇关于如何修复被 git rebase 破坏的 GitHub 拉取请求中的提交顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆