Git:以交互方式重新确定一系列提交的基准 [英] Git: Interactively rebase a range of commits

查看:94
本文介绍了Git:以交互方式重新确定一系列提交的基准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试rebase -i在我的历史中发生过几次提交.假设我有这样的日志:

I'm trying to rebase -i a few commits that occurred a while back in my history. Say I have a log like this:

* 5e32fb0 (HEAD -> master) Add latest feature
* 106c31a Add new feature
* 2bdac33 Add great feature
...100 other commits...
* 64bd9e7 Add test 3
* 3e1066e Add test 2
* 26c612d Add test 1
* 694bdda Initialize repo

,我要压缩3个测试提交.在这种情况下,git rebase -i HEAD~106不太实用.我正在寻找的是类似git rebase -i 64bd9e7:26c612d的东西.

and I want to squash the 3 test commits. In these circumstances, git rebase -i HEAD~106 isn't very practical. What I'm looking for instead is something like git rebase -i 64bd9e7:26c612d.

git有这种行为吗?如果是的话,我该如何使用它?

Does git have this sort of behaviour, and if so, how can I use it?

我看了这篇文章,但没有回答我的问题.

I had a look at this post, but it didn't answer my question.

推荐答案

为了挤压这三个提交,您需要重新编写 entire 存储库的历史记录.也就是说,将修改那些测试提交之后所有提交的提交哈希.我认为,最简单的方法是:

In order to squash those three commits, you'll need to re-write history for the entire repository. That is, all the commit hashes for commits after those test commits will be modified. The most straight-forward way to do it, in my opinion, is to:

  1. 创建一个临时分支并签出指向64bd9e7的地方.
  2. 将这三个提交压缩在一起.
  3. 签出您的主分支,并在64bd9e7之后立即将其重置为提交.
  4. 将其重新设置到您的临时分支上
  1. Create a temporary branch and checkout pointing at 64bd9e7.
  2. Squash the three commits together.
  3. Checkout your main branch, and reset it to the commit immediately after 64bd9e7.
  4. Rebase it onto your temporary branch

这篇关于Git:以交互方式重新确定一系列提交的基准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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