git 如何讓單個文件回退到指定的版本

1.進入到文件所在文件目錄,或者能找到文件的路徑
查看文件的修改記錄java

1
 $ git log MainActivity.java

結果:android

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
commit 7641210b242a95eed17827dd8159e76bdad6d619Author: ronanhardiman <liqiang.isman@gmail.com>Date:   Mon Apr 29 00:51:00 2013 +0800

    System.currentTimeMillis() 替代 timer 實現 連續兩次返回鍵退出

    System.currentTimeMillis() 替代 timer 實現 連續兩次返回鍵退出commit a4e215234aa4927c85693dca7b68e9976948a35eAuthor: kaxi4it <gyj_android@sina.com>Date:   Sat Apr 27 16:54:48 2013 +0800

    修正了退出程序的BUG

    用INT代替BOOL標記,修正了快速點擊返回鍵一直播放退出動畫的BUG,跳轉頁面後標記commit d31fcc01223407492310c1567a7b84ece1287368Author: yjl <yujilong@eoemobile.com>Date:   Mon Mar 25 12:09:21 2013 +0800

2.回退到指定的版本git

1
$ git reset a4e215234aa4927c85693dca7b68e9976948a35e MainActivity.java

結果github

1
2
3
Unstaged changes after reset:M       source/src/cn/eoe/app/ui/MainActivity.javasu@SUCHANGLI /e/eoeclient/android-app/source/src/cn/eoe/app/ui (master)

3.提交到本地參考app

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.更新到工做目錄ui

1
$ git checkout MainActivity.java

5.提交到遠程倉庫3d

1
$ git push origin master

若是提交須要用戶名密碼的話,會有提示;
結果code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
Username for 'https://github.com': com360Password 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 -> mastersu@SUCHANGLI /e/eoeclient/android-app/source/src/cn/eoe/app/ui (master)

這樣就把指定的文件回退到指定的版本了。直播

相關文章
相關標籤/搜索