标签:
有时候接手一份新代码时,看到某些文件的改动,但不清楚这个改动的作者和原因,想查看该文件的具体提交历史记录。
今天一个同事是这样做的,直接敲git log命令,然后再使用vim命令的搜索关键字的方法来查看该文件的提交记录,如下所示:
例如:我想查看frameworks/base/packages/SystemUI/AndroidManifest.xml该文件的提交记录,敲了git log命令后,直接按“/”然后加入该文件的路径,后就可以搜索该文件名作为关键字,然后按N和Ctrl+N进行上下搜索结果切换,如下所示:
这样的话,很慢很繁琐,效率比较慢。
下面我介绍一个比较快捷的方法来查看某个指定文件的提交记录,使用的还是git log命令,只是加了一些参数而已。
git log --pretty=oneline 文件名
例如:想搜索刚才的frameworks/base/packages/SystemUI/AndroidManifest.xml文件的提交记录,就可以使用命令:
oyp@buildServer3:~/E580$ git log --pretty=oneline frameworks/base/packages/SystemUI/AndroidManifest.xml 34b7ac981a39193ca78e0d4673ce66515c23988d [add a new feature to show the battery voltage value and level] 1.Support show the level of c1d6879f098775f1d703dfcfe814c4d726be47ad [Create MT6753-6M AP source repository]
如上所示,打印出来的就是针对文件frameworks/base/packages/SystemUI/AndroidManifest.xml文件的所有的改动历史,每一行最前面的那一长串数字就是每次提交形成的哈希值,接下来使用git show即可显示具体的某次的改动的修改。
下面就可以使用git show 命令查看具体的修改详情了。如:
git show <git提交版本号> <文件名>
git show 34b7ac981a39193ca78e0d4673ce66515c23988d frameworks/base/packages/SystemUI/AndroidManifest.xml这样指定版本号,指定文件的就可以直接查看该文件的修改详情,不要看该版本号其他文件的修改。如下所示:
oyp@buildServer3:~/E580$ git show 34b7ac981a39193ca78e0d4673ce66515c23988d frameworks/base/packages/SystemUI/AndroidManifest.xml commit 34b7ac981a39193ca78e0d4673ce66515c23988d Author: oyp <oyp@runbo.net> Date: Mon Nov 30 19:47:48 2015 +0800 [add a new feature to show the battery voltage value and level] 1.Support show the level of battery voltage (0-5 levels). 2.Support show the battery voltage value (accurate to two decimal places). Appllicable Project: E580 Appllicable model: All Except IKE new file: frameworks/base/packages/SystemUI/res/drawable-hdpi/battery_voltage_0.png new file: frameworks/base/packages/SystemUI/res/drawable-hdpi/battery_voltage_1.png new file: frameworks/base/packages/SystemUI/res/drawable-hdpi/battery_voltage_2.png new file: frameworks/base/packages/SystemUI/res/drawable-hdpi/battery_voltage_3.png new file: frameworks/base/packages/SystemUI/res/drawable-hdpi/battery_voltage_4.png new file: frameworks/base/packages/SystemUI/res/drawable-hdpi/battery_voltage_5.png new file: frameworks/base/packages/SystemUI/src/com/android/systemui/MyBatteryService.java new file: frameworks/base/packages/SystemUI/src/com/android/systemui/MyBootCompletedReceiver.java modified: frameworks/base/packages/SystemUI/AndroidManifest.xml modified: frameworks/base/packages/SystemUI/res/layout/system_icons.xml modified: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java modified: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java modified: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java diff --git a/frameworks/base/packages/SystemUI/AndroidManifest.xml b/frameworks/base/packages/SystemUI/AndroidManifest.xml old mode 100644 new mode 100755 index dfdc14c..5fb3545 --- a/frameworks/base/packages/SystemUI/AndroidManifest.xml +++ b/frameworks/base/packages/SystemUI/AndroidManifest.xml @@ -126,7 +126,11 @@ <!-- M: Add for data sim switch --> <uses-permission android:name="android.permission.WRITE_APN_SETTINGS"/> - + + <!-- added by ouyang start 2015-11-30 --> + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> + <!-- added by ouyang end 2015-11-30 --> + <application android:name=".SystemUIApplication" android:persistent="true" @@ -407,5 +411,14 @@ <action android:name="android.intent.action.LOCALE_CHANGED" /> </intent-filter> </receiver> + + <!-- added by ouyang start 2015-11-30 --> + <receiver android:name=".MyBootCompletedReceiver" > + <intent-filter> + <action android:name="android.intent.action.BOOT_COMPLETED"/> + </intent-filter> + </receiver> + <service android:name=".MyBatteryService"/> + <!-- added by ouyang end 2015-11-30 --> </application> </manifest>
这样的话,很高效、快速的查看指定文件的提交记录和记录详情。
====================================================================================
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:http://blog.csdn.net/ouyang_peng
====================================================================================
git学习------>如何用git log命令来查看某个指定文件的提交历史记录
标签:
原文地址:http://blog.csdn.net/ouyang_peng/article/details/50126603