3 回答

TA貢獻1794條經驗 獲得超7個贊
您需要做的是創建一個新提交,其詳細信息與當前HEAD提交相同,但其父級為的早期版本HEAD。git reset --soft將移動分支指針,以便下一次提交發生在與當前分支頭所在位置不同的提交之上。
# Move the current head so that it's pointing at the old commit
# Leave the index intact for redoing the commit.
# HEAD@{1} gives you "the commit that HEAD pointed at before
# it was moved to where it currently points at". Note that this is
# different from HEAD~1, which gives you "the commit that is the
# parent node of the commit that HEAD is currently pointing to."
git reset --soft HEAD@{1}
# commit the current tree using the commit details of the previous
# HEAD commit. (Note that HEAD@{1} is pointing somewhere different from the
# previous command. It's now pointing at the erroneously amended commit.)
git commit -C HEAD@{1}

TA貢獻1906條經驗 獲得超3個贊
通過以下方式查找修改后的提交:
git log --reflog
注意:--patch為了清楚起見,您可以添加以查看提交的正文。與相同git reflog。
然后通過以下方法將HEAD重置為以前的任何提交:
git reset SHA1 --hard
注意:將 SHA1 替換為實際的提交哈希。另請注意,此命令將丟失所有未提交的更改,因此您可以將它們存放在前面。或者,改用--soft保留最新的更改,然后提交。
然后在它上面挑選另一個提交:
git cherry-pick SHA1
- 3 回答
- 0 關注
- 983 瀏覽
添加回答
舉報