# Git

作者:Odboy (opens new window)

本站地址:https://blog.odboy.cn (opens new window)

# 变基至最新记录,并自动暂存本地修改(神技,谁用谁知道)
git pull origin master --rebase --autostash

# 撤销最后一次提交,保留更改的文件
git reset --soft HEAD~1

# 撤销最后一次提交,放弃所有变更
git reset --hard HEAD~1

# 暂存变更(需要切换分支,但不想提交当前变更时)
## 暂存更改
git stash
## 恢复更改
git stash pop

# 回滚到指定的commit,并保留工作目录和工作区的改动
git reset --soft <commit-hash>

# 回滚到指定的commit,并丢弃工作目录的改动
git reset <commit-hash>

# 回滚到指定的commit,并丢弃工作目录和暂存区的改动
git reset --hard <commit-hash>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
最近更新: 2025-03-24
Git

2017 - 2025 武林秘籍   |   赣ICP备17011078号