You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何git diff C C'与diff <(git show C) <(git show C')结果差异巨大?

问题原因解析

核心区别:git show vs git diff

  • git show <commit>:仅展示该提交自身相对于父提交的变更,也就是这个提交到底做了哪些修改。你这里C和C'是通过cherry-pick生成的,它们自身的修改内容完全一致,所以除了提交哈希,git show的输出几乎没有差异。
  • git diff <commit1> <commit2>:直接对比两个提交对应的完整仓库快照,也就是把两个提交下所有文件的内容做全面对比。

结合提交结构分析

你的仓库提交结构是:

A---B---C topic
     /
D---E---F---G---C'---H master
  • C的父提交是B,它的完整快照基于E→A→B的基础,再加上C自身的修改。
  • C'的父提交是G,它的完整快照基于E→F→G的基础,再加上C'自身的修改(和C的修改完全一致)。

master分支在E之后的F、G提交中,已经对MainActivity.java、MyTrial.java等文件做了修改,这些修改会被C'继承,但C所在的topic分支并没有这些变更。所以git diff C C'对比的是两个不同基础快照加上相同增量修改的结果,出现的大量差异其实来自F、G提交,而非C和C'自身的修改。

验证方法

如果要确认C和C'自身的修改完全一致,可以执行以下命令:

# 对比C和它父提交的差异
git diff C^ C
# 对比C'和它父提交的差异
git diff C'^ C'

这两个命令的输出应该完全相同。


命令输出验证

git show C 输出

~/foo$ git show 37a78fd9
commit 37a78fd9XXX...
Author: XXX XXX <XXX+XXX@users.noreply.github.com>
Date:   Thu Jun 9 15:05:14 2022 +0900

    May have fixed synchronization issue

diff --git a/Trial.java b/Trial.java
index 3e662af7..5dedcf37 100644
--- a/Trial.java
+++ b/Trial.java
@@ -11,6 +11,8 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -138,15 +140,17 @@ public class Trial implements Runnable, ActionSelector, SocketListener {
         Log.d("Episode", "End of episode:" + getEpisodeCount());
         // Waits for all image compression to finish prior to finishing flatbuffer
         long start = System.nanoTime();
-        for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
-            for (Future<?> future:timestepFutures){
+        synchronized (timeStepDataBuffer.imgCompFuturesTimeStep){
+            for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
+                for (Future<?> future:timestepFutures){
+                    future.get();
+                }
+            }
+            // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
+            for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
                 future.get();
             }
         }
-        // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
-        for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
-            future.get();
-        }
         long stop = System.nanoTime();
         long timediff = stop - start;
         flatbufferAssembler.endEpisode();

git show C' 输出

~/foo$ git show 5b5aa9b5
commit 5b5aa9b5XXX... (threadingIssue)
Author: XXX XXX <XXX+XXX@users.noreply.github.com>
Date:   Thu Jun 9 15:05:14 2022 +0900

    May have fixed synchronization issue

diff --git a/Trial.java b/Trial.java
index 3e662af7..5dedcf37 100644
--- a/Trial.java
+++ b/Trial.java
@@ -11,6 +11,8 @@ import java.io.IOException;
 import java.nio.ByteBuffer;
 import java.nio.charset.StandardCharsets;
 import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
@@ -138,15 +140,17 @@ public class Trial implements Runnable, ActionSelector, SocketListener {
         Log.d("Episode", "End of episode:" + getEpisodeCount());
         // Waits for all image compression to finish prior to finishing flatbuffer
         long start = System.nanoTime();
-        for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
-            for (Future<?> future:timestepFutures){
+        synchronized (timeStepDataBuffer.imgCompFuturesTimeStep){
+            for (Collection<Future<?>> timestepFutures: timeStepDataBuffer.imgCompFuturesEpisode){
+                for (Future<?> future:timestepFutures){
+                    future.get();
+                }
+            }
+            // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
+            for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
                 future.get();
             }
         }
-        // Waits for all timestep flatbuffer writes to finish prior to finishing flatbuffer
-        for (Future<?> future:flatbufferAssembler.flatbufferWriteFutures){
-            future.get();
-        }
         long stop = System.nanoTime();
         long timediff = stop - start;
         flatbufferAssembler.endEpisode();

diff <(git show C) <(git show C') 输出

仅显示提交哈希差异,验证两个提交的变更内容一致:

~/foo$ diff <(git show 37a78fd9) <(git show 5b5aa9b5)
1c1
< commit 37a78fd9XXX...
---
> commit 5b5aa9b5XXX...

git diff C C' 输出

显示的差异来自master分支F、G提交的内容,而非C/C'自身的修改:

diff --git a/MainActivity.java b/MainActivity.java
index a72a91f4..aa83e306 100644
--- a/MainActivity.java
+++ b/MainActivity.java
@@ -49,9 +49,9 @@ public class MainActivity extends AbcvlibActivity implements IOReadyListener {
         ------------------------------ Set MetaParameters ------------------------------
         --------------------------------------------------------------------------------
          */
-        TimeStepDataBuffer timeStepDataBuffer = new TimeStepDataBuffer(2);
-        MetaParameters metaParameters = new MetaParameters(this, 50, 1,
-                100000, 10000, inetSocketAddress, timeStepDataBuffer, getOutputs(), 1);
+        TimeStepDataBuffer timeStepDataBuffer = new TimeStepDataBuffer(200);
+        MetaParameters metaParameters = new MetaParameters(this, 50, 200,
+                100000, 1000, inetSocketAddress, timeStepDataBuffer, getOutputs(), 1);

         /*------------------------------------------------------------------------------
         ------------------------------ Define Action Space -----------------------------
diff --git a/MyTrial.java b/MyTrial.java
index b21efc73..148669b3 100644
--- a/MyTrial.java
+++ b/MyTrial.java
@@ -2,13 +2,7 @@ package xxx.serverlearning;

 import android.util.Log;

-import org.json.JSONArray;
-import org.json.JSONException;
-import org.json.JSONObject;
-
 import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.charset.StandardCharsets;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.ExecutionException;

...

内容的提问来源于stack exchange,提问作者topher217

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 10:37:03