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

Git 将最近提交的更改添加到过去提交的更改,git,version-control,Git,Version Control,我有一份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 fb8cbd242a2c686f36fc957dd1e866251be

我有一份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
commit 72d7e34f41b50b53992fb5d36276714d1aac4dc46(HEAD->main)
作者:Mateusz Urbanski
日期:4月22日星期四12:03:53 2021+0200
添加缺少的测试
提交FB8CBD242A2C68686F36FC957DD1E866251BE36FC5(源/主)
作者:Mateusz Urbanski
日期:星期三4月21日18:46:43 2021+0200
Todo模型
提交98cab0239ace028ff1421345a96525403276615c
作者:Mateusz Urbanski
日期:星期三4月21日14:10:14 2021+0200
用户模型
提交599de32cf46cbec9ae0d1dd52c4f046e49428e42
作者:Mateusz Urbanski
日期:星期三4月21日11:41:37 2021+0200
设置测试框架
我想从最新提交中获取所有更改
72d7e34f41b50b53992fb5d3627714d1aac4dc46
,并将这些更改添加到过去的提交中:
599de32cf46cbec9ae0d1dd52c4f046e49428e42
。 最简单的方法是什么?

如果您的意思是:

“我想去掉两个中间提交‘用户模型’和‘Todo模型’”,
使用git-rebase-i(
-i
代表“交互式”):

git-rebase
将应用刚才保存的脚本,并放弃这两个提交

如果你的意思是:

“我想将‘添加缺少的文本’修改应用到‘设置测试框架’,并将另外两个提交保持在其上”
再次使用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
$ 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