本文转载自:http://blog.csdn.net/ikscher/article/details/43851643

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 7641210b242a95eed17827dd8159e76bdad6d619
Author: ronanhardiman <liqiang.isman@gmail.com>
Date: Mon Apr 29 00:51:00 2013 +0800 System.currentTimeMillis() 替代 timer 实现 连续两次返回键退出 System.currentTimeMillis() 替代 timer 实现 连续两次返回键退出 commit a4e215234aa4927c85693dca7b68e9976948a35e
Author: kaxi4it <gyj_android@sina.com>
Date: Sat Apr 27 16:54:48 2013 +0800 修正了退出程序的BUG 用INT代替BOOL标记,修正了快速点击返回键一直播放退出动画的BUG,跳转页面后标记 commit d31fcc01223407492310c1567a7b84ece1287368
Author: yjl <yujilong@eoemobile.com>
Date: Mon Mar 25 12:09:21 2013 +0800

2.回退到指定的版本

1
$ git reset a4e215234aa4927c85693dca7b68e9976948a35e MainActivity.java

结果

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.提交到本地参考,注意不需要Git add。

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)

这样就把指定的文件回退到指定的版本了。

想深入了解为什么是这样操作的?请参考:http://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified 这篇文章。

git 如何让单个文件回退到指定的版本【转】的更多相关文章

  1. git 如何让单个文件回退到指定的版本

    1.进入到文件所在文件目录,或者能找到文件的路径查看文件的修改记录 1 $ git log MainActivity.java 结果: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

  2. 用git如何把单个文件回退到某一版本

    暂定此文件为a.jsp 1.首先到a.jsp所在目录: 通过 git  log a.jsp 查看a.jsp的更改记录 2.找到想要回退的版本号:例如 fcd2093 通过 git reset  fcd ...

  3. 【Git版本控制】git将单个文件回退到某一版本

    暂定此文件为a.jsp 1.进入到a.jsp所在目录,通过 git  log a.jsp查看a.jsp的更改记录 2.找到想要回退的版本号:例如 fcd2093 通过 git reset   fcd2 ...

  4. git操作记录(如何回退到某个历史版本,如何提交部分文件等方法)

    当前项目使用git管理代码,在使用的过程中会遇到一些问题,这里记录下 1.合并代码后 在合并组员的代码后会出现下面的界面,开始的时候都会关闭,重新打开,乐此不疲到忍无可忍 解决方法: 出现这种界面是要 ...

  5. reset 单个文件 回退

    git将单个文件恢复到历史版本的正确方法如下: git reset commit_id 文件路径 git checkout -- 文件路径

  6. IDEA Git回退到指定历史版本

    1.找到要回退的版本号(右击项目--> Git --> Show History -->选中要回退的版本-->Copy Revision Number): 2.打开idea的T ...

  7. git如何生成单个文件的补丁

    背景:有时候碰到一个commit包含了好几个文件的修改,但是我只需要其中一个文件的修改内容,那么这时候就需要以下方法来生成这一个文件对应修改内容的补丁 答:git format-patch " ...

  8. Git——快速重命名文件和查看commit提交版本【四】

    快速重命名文件 $ git mv README.md readme.md 使用git mv命令后直接commit即可,不再需要进行add或rm操作 查看版本历史 所有的参数都可以进行组合使用的,比如我 ...

  9. Git 生成.gitinore忽略文件

    Git  生成.gitinore忽略文件 CD到指定目录下: touch .gitinore .gitinore忽略文件 三种方法: # 以'#'开始的行,被视为注释.(#是注释的意思) # 忽略掉所 ...

随机推荐

  1. 关于对象字面量花括号{} key的类型

    原来对{}方式建立的实例化后的对象的key,理解不清,只知道,数组加不加“”,反正都是字符,现在要理解下,到底怎么回事?返回结果是 var a={}; a[1]="a"; a[&q ...

  2. Relocation(状压DP)

    Description Emma and Eric are moving to their new house they bought after returning from their honey ...

  3. 推荐一个 Java 实体映射工具 MapStruct

    声明: 1.DO(业务实体对象),DTO(数据传输对象). 2.我的代码中用到了 Lombok ,不了解的可以自行了解一下,了解的忽略这条就好. 在一个成熟的工程中,尤其是现在的分布式系统中,应用与应 ...

  4. PAT (Advanced Level) 1038. Recover the Smallest Number (30)

    注意前导零的消去. #include <iostream> #include <string> #include <sstream> #include <al ...

  5. Segments--poj3304(判断直线与线段之间的关系)

    http://poj.org/problem?id=3304 给你几条线段  然后 让你找到一条直线让他在这条直线上的映射有一个重合点 如果有这条直线的话  这个重合的部分的两个端点一定是某两条线段的 ...

  6. Callable线程

    写一个Callable线程 import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; im ...

  7. java 返回json数据

    Student st1 = new Student(1, "dg", 18, new Date());            Student st2 = new Student(2 ...

  8. 【APUE】信号量、互斥体和自旋锁

    http://www.cnblogs.com/biyeymyhjob/archive/2012/07/21/2602015.html http://blog.chinaunix.net/uid-205 ...

  9. 小心入怀Yaf

    http://www.laruence.com/2015/05/14/3021.html, 鸟哥文章 看了这个文章,更加要小心的对待 Yaf Yar 框架了. 不正确 glib 有一定的了解进来就是深 ...

  10. RHEL 启动系统及故障排除

    一:Linux的启动过程: 开机加电自检->MBR引导(boot loader占446字节,分区列表64字节,magic占2字节)-->grub菜单(MBR是grub的第一个字段,第二个字 ...