notes icon indicating copy to clipboard operation
notes copied to clipboard

Git 删除指定提交 or git reset

Open lanlin opened this issue 8 years ago • 1 comments

场景

当你提交了不应该提交的文件,或者提交了有严重问题的代码时。希望能够删除掉那次提交。

术语

working copy, working tree = 工作目录, 工作副本 index, stage = 缓冲区, 暂存区

方法

git reset --mixed 版本hash
// 重置到指定版本,此时从该版本到HEAD的所有提交都被重置。
// 从该版本到HEAD的所有修改都会出现在 “工作目录(working tree)” 里面,
// 处于 “未暂存(Changes not staged)” 的状态

git reset --soft 版本hash
// 重置到指定版本,此时从该版本到HEAD的所有提交都被重置。
// 从该版本到HEAD的所有修改都会出现在 “工作目录(working tree)” 里面,
// 处于 “已暂存未提交(Changes to be committed)” 的状态

git reset --hard 版本hash
// 完全重置到该版本,不保留任何修改。
// “工作目录(working tree)” 里面不会看到该版本之后的修改结果。

三种模式说明图:yes 为会重置修改,no 为会保留修改 image

说明

--mixed 为默认采用的方式,也就是说直接执行 git reset 版本hash 时,默认就会用 mixed 的形式。 image

lanlin avatar Apr 18 '17 04:04 lanlin

git 删除未推送的提交 or delete unpushed git commits #10

lanlin avatar Sep 09 '20 10:09 lanlin