1. Home
  2. Docs
  3. git
  4. 常用操作
  5. 撤销-恢复-移除

撤销-恢复-移除

  1. 查看历史版本 git log
  2. 回滚到指定commit id git reset --hard fb479960c0cec5549463ae123d70bdd72ccf6be7
  3. 强制远程回滚 git push origin master --force

Tip: gitlab需要把受取消受保护限制

1) 此时如果想撤销commit,同时保留git add

git reset --soft HEAD^

2) 删除工作空间改动代码,撤销commit,撤销git add .

git reset --hard HEAD^

3) 不删除工作空间改动代码,撤销commit,并且撤销git add .

git reset --mixed HEAD^

移除没有追踪的文件

git clean -d -f -n # 参数n先查看 将要被移除的文件

git clean -d -f # 移除没有追踪的文件

恢复某个文件或文件夹到指定的版本

git checkout [commit] 文件或文件夹路径

撤销恢复

git reset 文件或文件夹路径

撤销pull

  1. 查看历史记录 git reflog
  2. 撤销到指定版本 git reset --hard HEAD@{n} eg: it reset --hard 40a9a83

相关资料

多个commit的撤销与合并

you are not allowed to push

git撤销pull命令

Tags
Was this article helpful to you? Yes No

How can we help?