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 关注
- 948 浏览
添加回答
举报