将最新提交的更改添加到过去的提交

Adding changes from the latest commit to the commit from the past

我有一个 git 具有以下提交的回购协议:

commit 72d7e34f41b0b53992fb5d36276714d1aac4dc46 (HEAD -> main)
Author: Mateusz Urbański <mateuszurbanski@yahoo.pl>
Date:   Thu Apr 22 12:03:53 2021 +0200

    Add missing test

commit fb8cbd242a2c686f36fc957dd1e866251be36fc5 (origin/main)
Author: Mateusz Urbański <mateuszurbanski@yahoo.pl>
Date:   Wed Apr 21 18:46:43 2021 +0200

    Todo model

commit 98cab0239ace028ff1421345a96525403276615c
Author: Mateusz Urbański <mateuszurbanski@yahoo.pl>
Date:   Wed Apr 21 14:10:14 2021 +0200

    User model

commit 599de32cf46cbec9ae0d1dd52c4f046e49428e42
Author: Mateusz Urbański <mateuszurbanski@yahoo.pl>
Date:   Wed Apr 21 11:41:37 2021 +0200

    Setup Test Framework

我想从我最近的提交 72d7e34f41b0b53992fb5d36276714d1aac4dc46 中获取所有更改,并将这些更改添加到过去的提交中:599de32cf46cbec9ae0d1dd52c4f046e49428e42。 最简单的方法是什么?

如果你的意思是:

"我想摆脱两个中间提交 'User model' 和 'Todo model'",
使用 git rebase -i-i 代表“交互式”):

# specify the *parent* of the first commit :
$ git rebase -i 599de32cf^

# an editor will open, with instuctions on how to modify your history
# - delete the two commits you want to discard from these instructions
# save & exit

git rebase 将应用您刚刚保存的脚本,并丢弃这两个提交。

如果你的意思是:

“我想将 'Add missing text' 修改应用到 'Setup Test Framework',并在其之上保留其他两个提交”,
再次使用 git rebase -i :

$ git rebase -i 599de32cf^

# in the editor that opens :
# - cut the line 'Add missing text' and paste it right after the 'Setup Test Framework' line
# - change the verb (the first word on the line) for 'Add missing text' to 'fixup'
# save & exit