我正在修改先前提交“commit2”的内容,步骤如下:
#1 checkout the commit we want to modify
git checkout ad4fe51
#2 amend the commit with new changes
git add . && git commit --amend --no-edit
#3 remove files from folder
git rm -rf .
#4 return
git checkout -
#5 rebase
git rebase --onto @{-1} ad4fe51
但是,在第 5 步,它会推回提交中修改的内容 (#2) 如果我调用 Push origin,commit2 会正确包含所有修改,但是,
“commit7”将包含
{ commit7.txt, newfile1.txt, newfile2.txt }
如何避免这种情况? 我按照以下步骤录制 gif:https://i.imgur.com/qc9fVeA.gif
我认为如果您从git rebase
开始
,您的生活会更轻松:
git rebase -i COMMIT^
例如,如果您想编辑提交ad4fe51
,请运行:
git rebase -i ad4fe51^
pick
更改为
edit
并保存列表。
git add
文件。
git rebase --continue
。