3 回答

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
您需要做的是創(chuàng)建一個(gè)新提交,其詳細(xì)信息與當(dāng)前HEAD提交相同,但其父級(jí)為的早期版本HEAD。git reset --soft將移動(dòng)分支指針,以便下一次提交發(fā)生在與當(dāng)前分支頭所在位置不同的提交之上。
# 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貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超3個(gè)贊
通過以下方式查找修改后的提交:
git log --reflog
注意:--patch為了清楚起見,您可以添加以查看提交的正文。與相同git reflog。
然后通過以下方法將HEAD重置為以前的任何提交:
git reset SHA1 --hard
注意:將 SHA1 替換為實(shí)際的提交哈希。另請(qǐng)注意,此命令將丟失所有未提交的更改,因此您可以將它們存放在前面?;蛘撸挠?-soft保留最新的更改,然后提交。
然后在它上面挑選另一個(gè)提交:
git cherry-pick SHA1
- 3 回答
- 0 關(guān)注
- 992 瀏覽
添加回答
舉報(bào)