转自: https://blog.csdn.net/u011361138/article/details/80959438
1. 本地
(1) 执行了git add操作, 想取消暂存
git reset head
git reset head <filename>
git reset --hard HASH # 返回到某个节点,不保留修改。
git reset --soft HASH # 返回到某个节点。
1
2
3
4
(2) 撤销对文件的修改
git checkout head readme.txt todo.txt # 撤销1~2个文件的修改
git checkout head *.txt # 撤销对所有txt文件的修改
git checkout head # 撤销对所有文件的修改
git checkout . # 撤销本地所有修改的, 没有的提交的内容,都返回到原来的状态
1
2
3
4
(3) 已经执行了git commit,修改后不想在产生新的提交历史记录,最终你只会有一个提交 - 第二次提交将代替第一次提交的结果
git commit -m 'initial commit'
git add 忘记提交的文件
git commit --amend
1
2
3
(4) 回退到指定的版本
git reset --hard 版本提交的id # 切换到指定的提交id
git reset --hard HEAD^ #回退到上个版本
1
2
2. 远程
首先在本地切换到到回退的指定版本
git reset --hard 版本提交的id
git reset --hard HEAD^ #回退到上个版本
1
2
强制push到远程
git push -f origin master
---------------------
作者:范翻番樊
来源:CSDN
原文:https://blog.csdn.net/u011361138/article/details/80959438
版权声明:本文为博主原创文章,转载请附上博文链接!