案例1
- 比如工作区有一个文件叫test.txt文档,你需要删除,那么使用如下命令即可:
git rm “test.txt” - 如果想撤销删除的文件,使用如下命令
git reset HEAD test.txt
git checkout test.txt
案例2
- 如果你使用了git rm “test.txt” + git commit -m “remove test.txt”
- 此时你需要回滚到之前的版本:
git log找到你需要回滚的版本
git checkout hash-id,这里的hash-id就是log中的一串字符,比如10db64ae993878972095cd90b8721f1466b11d9f
案例3
- 如果你在案例2的commit基础上,还进行了push操作,需要执行以下代码:
git reset --hard hash-id
git push --force-with-lease origin main