为什么有些 git 提交比它们的父提交更早?

why some git commits are older than their parent?

我正在查看 apache-drill 提交 3efc2eca and I realized that it is older than its parent commit 8614bae

我还有其他一些类似的观察结果。 我该如何解释它们?

git 中的提交历史是可重写的。有很多方法可以发生这种情况。最可能的方式是提交在创建后 rebased

您可以使用交互式变基更改 git 历史记录,例如:

git rebase --interactive|-i HEAD~(number of commits)

场景如下:

$ git commit -m 'Commit 1'
$ git commit -m 'Commit 2'
$ git rebase -i HEAD~2
  // changing only 'Commit 1'
  edit bae2ea4 Commit 1
  pick 0e25612 Commit 2
$ git add .
$ git commit --amend
$ git rebase --continue

在这些之后 'Commit 2' 将比它的父 'Commit 1'

您应该记住,不建议您在更改发布(推送)后重写历史记录。