Git 提交压缩(rebase -i):提交实际上是如何工作的?

发布于 2024-09-11 23:00:58 字数 292 浏览 1 评论 0原文

我不太明白提交是如何用 git rebase -i 压缩的。我想知道一件事:

如果我的 rebase -i 生成这个列表:

pick A Last commit

pick B Commit

pick C Some other commit

我应该压缩提交 A 和 B 还是 B 和 C?问题是 git 在这种情况下表示它将把 D..A 重新设置为 D(D 是在此之前的最后一次提交),而不是将 C..A 重新设置为 C,这对我来说是有意义的。 D 根本没有显示,那为什么要这样说呢?

I don't quite understand how the commits are squashed with git rebase -i. There is one thing I was left wondering:

If my rebase -i produces this list:

pick A Last commit

pick B Commit

pick C Some other commit

Should I squash commits A and B or B and C? Problem is git said in this case that it would rebase D..A onto D (D being the last commit before this) rather than C..A onto C which would make sense to me. D is not shown at all, so why word it like that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不必你懂 2024-09-18 23:00:58

问题是 git 术语中的 D..A 意思是“从 D 到 A 不包括 D 本身”。如果你查看 git-rev-list 手册页,你会看到

符号“..”可以用作“^”的简写

意思是“列出包含但未包含在中的所有提交以及所做的更改。 by D 本身包含在 D commit 中,因此它不包含在表示为 D..A 的列表中

。正确的说法是 git rebase -i D 影响 D..HEAD

The thing is that D..A in git terminology means "from D to A not including D itself". If you look into git-rev-list manual page, you'll see that

notation "<commit1>..<commit2>" can be used as a short-hand for "^<commit1> <commit2>"

which means "list all commits that are included in <commit2>, but are not included in <commit1>. And the changes made by D itself are included in D commit. So it's not included in list denoted as D..A.

That's why it's correct to say that git rebase -i D affects D..HEAD.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文