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



我有一个git repo,它有以下提交:

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。最简单的方法是什么?

如果您的意思是:

"我想去掉两个中间提交"用户模型"one_answers"Todo模型">
使用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将应用刚才保存的脚本,并放弃这两个提交。

如果你的意思是:

"我想将"添加缺少的文本"修改应用于"设置测试框架",并将另外两个提交放在上面">
再次使用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

最新更新