如何使用 git rebase -i 进行一系列提交?
我是否可以使用不包括最新提交的变基来压缩本地功能/主题分支的一系列提交?这是我想在合并并推送到公共存储库之前准备的提交。
我工作得很快,做了一些小改动,标题和描述很糟糕,我想将它们压缩成两到三个独立的逻辑提交,并附上很好的评论。我是否可以选择 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以使用 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.因此,并不完全清楚“不包括”最近的提交是什么意思,但是当您执行
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.