我们在工作中常碰到同一份代码被多个同事修改的问题,那么想找到代码的某一行是谁修改的呢 ? git blame 命令就派上用场啦 ~~~
如: git blame Solution.java
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 18) public static void main(String[] args) {
427d1c00 (duxinglangzi 2018-03-26 17:02:48 +0800 19) int[] nums = {-1, 0, 1, 2, -1, -4};
427d1c00 (duxinglangzi 2018-03-26 17:02:48 +0800 20) int target = 0;
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 21)
427d1c00 (duxinglangzi 2018-03-26 17:02:48 +0800 22) int[] result = threeSum(nums,target);
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 23) //System.out.println(result);
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 24) System.out.println(Arrays.toString(result));
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 25) }
显示顺序依次为: 版本号、作者、时间、行号 、代码行
如果代码行数过多,那么可以使用 -L 来通过行号区间查找
如: git blame Solution.java -L 18,23
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 18) public static void main(String[] args) {
427d1c00 (duxinglangzi 2018-03-26 17:02:48 +0800 19) int[] nums = {-1, 0, 1, 2, -1, -4};
427d1c00 (duxinglangzi 2018-03-26 17:02:48 +0800 20) int target = 0;
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 21)
427d1c00 (duxinglangzi 2018-03-26 17:02:48 +0800 22) int[] result = threeSum(nums,target);
a2b1a432 (duxinglangzi 2018-03-22 18:12:15 +0800 23) //System.out.println(result);
敲黑板: git blame [filename] -L 开始行号,结束行号
注意了 -L 一定要大写的 L
git blame 命令到这里就结束啦~~~~~~~~~~~~~~~~
另外有朋友看到某一行代码的版本号和作者之后,想看这个作者在这个版本号下还提交了那些内容 ? 这时候可以使用 git show commitID
来实现。
如: git show 427d1c00
public static void main(String[] args) {
- int[] nums = {5,1,3,10,26,35};
- int target = 26;
+ int[] nums = {-1, 0, 1, 2, -1, -4};
+ int target = 0;
- int[] result = binarySearch(nums,target);
+ int[] result = threeSum(nums,target);
//System.out.println(result);
System.out.println(Arrays.toString(result));
}
欢迎到我github 交流讨论: https://github.com/duxinglangzi