Git 在分离状态下合并提交

Git 在分离状态下合并提交,git,version-control,Git,Version Control,比方说,我在master branch中有以下提交 -> step-4 -> step-3 -> step-2 -> step-1 -> step-0 然后我通过git checkout临时切换到步骤0。 现在我想添加一个文件,比如newfile.txt到提交中。我看到了关于重定基址和樱桃采摘的其他问题,但这并不能解决问题。 这里的问题是,这个newfile.txt和一些其他文件已经在其他提交步骤中提交。但我也希望在步骤0中提交。选项1 您可以使用以下命令来满足您

比方说,我在master branch中有以下提交

-> step-4
-> step-3
-> step-2
-> step-1
-> step-0
然后我通过git checkout临时切换到步骤0。 现在我想添加一个文件,比如newfile.txt到提交中。我看到了关于重定基址和樱桃采摘的其他问题,但这并不能解决问题。 这里的问题是,这个newfile.txt和一些其他文件已经在其他提交步骤中提交。但我也希望在步骤0中提交。

选项1 您可以使用以下命令来满足您的要求:

git checkout <commit for step-0>
touch newfile.txt
git add .
git commit --amend -am 'info'
git rebase --onto HEAD <commit for step-0> master
输入i将拾取更改为编辑,然后输入Esc和:wq

在重新设定基准期间:

touch newfile.txt 
git add .
git commit --amend
git rebase --continue

是的,它会将提交从步骤1到步骤4的基础重新设置到您当前的头部,并将其命名为master。我还添加了另一个选项供您参考。
touch newfile.txt 
git add .
git commit --amend
git rebase --continue