Reverse squash a commit, aka act as if an older commit had been part of a newer one?

huangapple go评论54阅读模式
英文:

Reverse squash a commit, aka act as if an older commit had been part of a newer one?

问题

我有一个代码仓库,每周四提交一次。
今天,在提交后,查看日志时,我注意到我在上周三提交了一次。但是那些更改应该在上周四提交!看来我在那个周三意外地运行了一个提交,而我以为我已经取消了。

我尝试了 git rebase -i,但它只允许我将较新的周四提交合并到较旧的周三提交中,结果是在周三只有一个提交。我想要相反的效果!fixup -c 看起来可能做我想要的事情,但也可能不行,而且我不知道如何恢复。
重新排序提交(类似问题的回答建议的方式)似乎也不符合我的要求,因为我想要保留较新的提交描述和时间戳,丢弃旧的提交。

所以:我该如何才能使上周只有周四的提交,而周三的提交更改也成为其一部分,就好像从未发生过?

英文:

I have a repository where I commit once a week every Thursday.
Today, after committing, when looking at the log, I noticed that I had made a commit on Wednesday last week.
But those changes should have been committed on Thursday last week!
It seems I accidentally ran a commit back on that Wednesday, that I thought I had aborted.

I tried git rebase -i, but it only lets me squash the newer Thursday commit into the older Wednesday one, resulting in one commit on Wednesday. I want the reverse! fixup -c looks like it might do what I want, but it may not, and then I would not know how to recover.
Reordering commits (as suggested in an answer to a similar question) also doesn’t seem to fit the bill, as I want the newer commit description and time stamp, and discard the old one.

So: How do it get there to be only the Thursday commit for last week, with the Wednesday commit changes being part of it. as if it never happened?

答案1

得分: 1

在交互式变基期间,同时交换这两行,并通过将pick更改为s来压缩现在较低的提交。您将被要求提供包含两个原始提交的新提交消息。

您可以先创建新分支来进行您的更改实验。

英文:

During the interactive rebase both swap the lines and squash the now lower commit by changing pick to s. You will be asked for new commit message with both original ones presented.

You can create new branch to experiment with your changes first.

huangapple
  • 本文由 发表于 2023年7月28日 01:16:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76782086.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定