十分钟学会常用git撤销操作,全面掌握git的时光机
pz1234567
2022年10月17日 09:55

00:21 git的4个区域

Disk, Staging,Local,Remote

00:35 Disk

git init

git diff

01:05 撤销还未缓存的修改

git status -> Changes not staged for commit(红色)

git checkout <changed_file>

(git restore <changed_file>)

01:46 撤销缓存区中的修改

git status -> Changes to be commited(绿色)

git reset <changed_file>

(git restore --staged <changed_file>)

02:38 撤销D和S中的修改

git checkout HEAD <chaned_file>

03:06 撤销提交的版本

git reset --soft HEAD~1

03:55 非软撤销

git reset HEAD~1

撤销 commit 版本同时清除 add 添加的缓存

04:24 撤销 L+S+D

git reset --hard HEAD~1

完全回滚(撤销已经提交的版本、放弃已经添加的缓存、甚至本地的修改)

05:10 reset vs rever

和git reset不同,git revert 本质上是增加一个 反相的commit

07:14 revert只能前进不许后退

在公有分支上 只能前进 不许后退

08:41 私有分支上可以使用reset

不过同步时要使用 git push -f