如何使用 git rebase -i 进行一系列提交?

发布于 2024-12-09 13:57:05 字数 302 浏览 0 评论 0原文

我是否可以使用不包括最新提交的变基来压缩本地功能/主题分支的一系列提交?这是我想在合并并推送到公共存储库之前准备的提交。

我工作得很快,做了一些小改动,标题和描述很糟糕,我想将它们压缩成两到三个独立的逻辑提交,并附上很好的评论。我是否可以选择 329aed9 和 af39283 之间的一系列提交,这些提交可能位于此功能分支的简短历史记录中的任何点?

git rebase -i RANGE_START_COMMIT_ID RANGE_LAST_COMMIT_ID

谢谢!

Can I squash a range of commits for a local feature/topic branch using rebase that does not include the most recent commit? This is for commits that I want to prepare before they get merged and pushed to a public repo.

I was working quickly and made a bunch of minor changes with poor titles and descriptions that I want to squash into two or three separate logical commits with a great comments. Can I select a range of commits between 329aed9 and af39283 that could be at any point in this feature branch's short history?

git rebase -i RANGE_START_COMMIT_ID RANGE_LAST_COMMIT_ID

Thanks!

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

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

发布评论

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

评论(2

放肆 2024-12-16 13:57:05

您始终可以使用 git checkout -b new_branch af39283 创建一个新分支,然后对其进行变基。但是,如果您想在将来的某个时间点包含稍后的提交,则也无法回避对它们进行变基。提交的 SHA1 取决于其所有祖先提交。

You could always create a new branch with git checkout -b new_branch af39283, and then rebase that. However, if you want to include the later commits at some future point, there's no getting around rebasing them as well. The SHA1 for a commit depends on all its ancestor commits.

戏蝶舞 2024-12-16 13:57:05

因此,并不完全清楚“不包括”最近的提交是什么意思,但是当您执行 rebase -i 时,您可以压缩/重新排序/reword/fixup/remove先前的提交,而无需对最后一次提交执行任何操作。当然,您正在重写它下面的历史记录,因此它的差异将被重新应用,并且它将是变基之后的一个不同的提交对象,但由于您还没有公开推送它(并且您正在重写它的其余部分) )这应该不重要。

So, it's not entirely clear what you mean by "not including" the most recent commit, but when you do a rebase -i you're able to squash/re-order/reword/fixup/remove prior commits without having to do anything to the last commit. You're rewriting the history underneath it of course, so its diff will be re-applied and it will be a different commit object following the rebase, but since you haven't pushed this publicly (and you're rewriting the rest of it) that shouldn't matter much.

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