我正在尝试删除revert
我的 Git 存储库开发分支上的最后 2 次提交,而不是。尚未推送提交。
我将如何在不丢失更改的情况下执行此操作?
我正在尝试删除revert
我的 Git 存储库开发分支上的最后 2 次提交,而不是。尚未推送提交。
我将如何在不丢失更改的情况下执行此操作?
在开发分支上,您将使用
git reset HEAD~2
这会将 HEAD 指针重置为当前之前的提交 2,而不会丢失更改。
以下是帮助的摘录:
git reset [-q] [<tree-ish>] [--] <paths>...
This form resets the index entries for all <paths> to their state
at <tree-ish>. (It does not affect the working tree, nor the
current branch.)
--mixed
Resets the index but not the working tree (i.e., the changed
files are preserved but not marked for commit) and reports what
has not been updated. This is the default action.
因此,它只重置索引,而不是树。您的文件的更改会保留,不会添加到索引中。如果需要,请使用以下--soft
标志:
--soft
Does not touch the index file nor the working tree at all (but
resets the head to <commit>, just like all modes do). This
leaves all your changed files "Changes to be committed", as git
status would put it.
我认为您想要做的是压缩最后 2 次提交。您可以通过交互式变基来做到这一点。
git rebase -i HEAD~3
然后相应地将最后 2 个提交标记为f
(fixup) 或s
(squash)。
Here's a tutorial on interactive rebasing