场景: 对于某个Git控制下的文件进行了修改,但是改的不满意,想退回到改之前的版本。
解决方法:
1 ,获取要回退到的提交的hash代码
2 ,checkout对应的以本,格式为: git checkout <hash> <filename>
举例:
回退所有文件: git checkout d98a0f565804ba639ba46d6e4295d4f787ff2949
回退某个文件: git checkout d98a0f565804ba639ba46d6e4295d4f787ff2949 src/main/main.c
丢弃本地所有更改,恢复到远程
git checkout master git branch -D test_feature # see note about -D below git checkout test_feature # should track origin/test_feature
git 放弃本地修改,远程分支强制覆盖本地
git fetch --all //只是下载代码到本地,不进行合并操作
git reset --hard origin/分支名如master //把HEAD指向最新下载的版本