我想删除 Git 仓库 develop 分支上的最新两个提交(不是“还原”)。这些提交尚未推送到远程分支。
请问我该如何处理,以免丢失更改内容?
我想删除 Git 仓库 develop 分支上的最新两个提交(不是“还原”)。这些提交尚未推送到远程分支。
请问我该如何处理,以免丢失更改内容?
在develop分支上,您需要使用
git reset 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.
--soft
选项,更改将会被暂存,而在这种情况下,更改将作为本地修改。根据 OP 的要求,两者都可以使用。 - Rohit Jain--mixed
。 - Chris Martingit rebase -i HEAD~3
然后相应地将最后2个提交标记为f
(修复)或s
(压缩)。