本文转自:http://blog.sina.com.cn/s/blog_6a2787d40102uzj1.html
1.进入到文件所在文件目录,或者能找到文件的路径
查看文件的修改记录
1 |
$ git log MainActivity.java |
结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
commit 7641210b242a95eed17827dd8159e76 |
2.回退到指定的版本
1 |
$ git reset a4e215234aa4927c85693dca |
结果
1 2 3 |
Unstaged changes after reset: M source/src/cn/eoe/app/ui/MainActivity.java su@SUCHANGLI /e/eoeclient/android-app/source/src/cn/eoe/app/ui (master) |
3.提交到本地参考
1 |
$ git commit -m "revert old file because yjl commmit have a bug" |
结果
1 2 3 |
[master 874e01a] revert old file because yjl commmit have a bug 1 file changed, 26 insertions(+), 19 deletions(-) su@SUCHANGLI /e/eoeclient/android-app/source/src/cn/eoe/app/ui (master) |
4.更新到工作目录
1 |
$ git checkout MainActivity.java |
5.提交到远程仓库
1 |
$ git push origin master |
如果提交需要用户名密码的话,会有提示;
结果
1 2 3 4 5 6 7 8 9 10 |
Username for 'https://github.com': com360 Password for 'https://com360@github.com': Counting objects: 17, done. Delta compression using up to 4 threads. Compressing objects: 100% (7/7), done. Writing objects: 100% (9/9), 860 bytes, done. Total 9 (delta 5), reused 0 (delta 0) To https://github.com/com360/android-app.git 7db7346..874e01a master -> master su@SUCHANGLI /e/eoeclient/android-app/source/src/cn/eoe/app/ui (master) |
这样就把指定的文件回退到指定的版本了。