考虑文件 (1.c) 包含三个函数以及作者 M 和 J 所做的更改。如果有人运行git blame 1.c
,他将得到以下输出:
^869c699 (M 2012-09-25 14:05:31 -0600 1)
de24af82 (J 2012-09-25 14:23:52 -0600 2)
de24af82 (J 2012-09-25 14:23:52 -0600 3)
de24af82 (J 2012-09-25 14:23:52 -0600 4) public int add(int x, int y) {
de24af82 (J 2012-09-25 14:23:52 -0600 5) int z = x+y;
de24af82 (J 2012-09-25 14:23:52 -0600 6) return z;
de24af82 (J 2012-09-25 14:23:52 -0600 7) }
de24af82 (J 2012-09-25 14:23:52 -0600 8)
^869c699 (M 2012-09-25 14:05:31 -0600 9) public int multiplication(int y, int z){
^869c699 (M 2012-09-25 14:05:31 -0600 10) int result = y*z;
^869c699 (M 2012-09-25 14:05:31 -0600 11) return temp;
^869c699 (M 2012-09-25 14:05:31 -0600 12) }
^869c699 (M 2012-09-25 14:05:31 -0600 13)
^869c699 (M 2012-09-25 14:05:31 -0600 14) public void main(){
de24af82 (J 2012-09-25 14:23:52 -0600 15) //this is a comment
de24af82 (J 2012-09-25 14:23:52 -0600 16) }
现在,如果作者 A 改变了multiplication()
and add()
发挥作用并提交更改,git blame
可以检测代码的移动。请参阅以下输出:
$ git blame -C -M e4672cf82 1.c
^869c699 (M 2012-09-25 14:05:31 -0600 1)
de24af82 (J 2012-09-25 14:23:52 -0600 2)
de24af82 (J 2012-09-25 14:23:52 -0600 3)
e4672cf8 (M 2012-09-25 14:26:39 -0600 4)
de24af82 (J 2012-09-25 14:23:52 -0600 5)
^869c699 (M 2012-09-25 14:05:31 -0600 6) public int multiplication(int y, int z){
^869c699 (M 2012-09-25 14:05:31 -0600 7) int result = y*z;
^869c699 (M 2012-09-25 14:05:31 -0600 8) return temp;
^869c699 (M 2012-09-25 14:05:31 -0600 9) }
^869c699 (M 2012-09-25 14:05:31 -0600 10)
^869c699 (M 2012-09-25 14:05:31 -0600 11) public void main(){
de24af82 (J 2012-09-25 14:23:52 -0600 12) //this is a comment
e4672cf8 (M 2012-09-25 14:26:39 -0600 13) }
de24af82 (J 2012-09-25 14:23:52 -0600 14) public int add(int x, int y){
de24af82 (J 2012-09-25 14:23:52 -0600 15) int z = x+y;
de24af82 (J 2012-09-25 14:23:52 -0600 16) return z;
e4672cf8 (M 2012-09-25 14:26:39 -0600 17) }
但是,如果我尝试运行git diff
在这两个修订之间,它无法检测到函数更改其位置并给出以下输出:
$ git diff -C -M de24af8..e4672cf82 1.c
diff --git a/1.c b/1.c
index 5b1fcba..56b4430 100644
--- a/1.c
+++ b/1.c
@@ -1,10 +1,7 @@
-public int add(int x, int y){
- int z = x+y;
- return z;
-}
+
public int multiplication(int y, int z){
int result = y*z;
@@ -13,4 +10,8 @@ public int multiplication(int y, int z){
public void main(){
//this is a comment
-}
\ No newline at end of file
+}
+public int add(int x, int y){
+ int z = x+y;
+ return z;
+}
\ No newline at end of file
我的问题是:
如何在获取 diff 输出时强制检测代码移动?有可能吗?
-
Git diff 可以通过多个选项来应用。例如--minimal
, --patience
。我如何在这里应用这些选项?我尝试了其中一个,但出现以下错误:
$ git diff --minimal de24af8..e4672cf82 1.c
usage: git diff <options> <rev>{0,2} -- <path>*
任何人都可以建议/给出如何正确添加这些选项的示例吗?