【问题标题】:Inconsistency between "git show" and "git log --" when tracking changes in a subdirectory跟踪子目录中的更改时“git show”和“git log --”之间的不一致
【发布时间】:2017-06-21 13:13:48
【问题描述】:

我想查找系统历史的子目录中的更改。为此,我使用

git log -- $subdirectory

根据this,这就足够了。 “git log -- $subdirectory”的结果中有一些没有出现的提交;但是根据

git show $sha

,他们改变了子目录。

例如,在apache-accumulo 中,当我查看this 时使用

git show 31ee26b8ac41844f2a647a5d1484f47da731872a

,我看到它改变了“core/src/main”。更具体地说,我得到以下回复

commit 31ee26b8ac41844f2a647a5d1484f47da731872a
Author: Eric C. Newton <eric.newton@gmail.com>
Date:   Wed Mar 11 14:37:39 2015 -0400

    ACCUMULO-3423 fixed replication bugs with recent refactorings in StatusUtil

diff --git a/core/src/main/java/org/apache/accumulo/core/replication/StatusUtil.java b/core/src/main/java/org/apache/accumulo/core/replication/StatusUtil.java
index d8ec403..cdb6963 100644
--- a/core/src/main/java/org/apache/accumulo/core/replication/StatusUtil.java
+++ b/core/src/main/java/org/apache/accumulo/core/replication/StatusUtil.java
@@ -155,7 +155,7 @@ public class StatusUtil {
   /**
    * @return A {@link Status} for an open file of unspecified length, all of which needs replicating.
    */
-  public static Status openWithUnknownLength(long timeCreated) {
+  public static synchronized Status openWithUnknownLength(long timeCreated) {
     return INF_END_REPLICATION_STATUS_BUILDER.setCreatedTime(timeCreated).build();
   }

diff --git a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/TabletServerLogger.java b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/TabletServerLogger.java
index 46101c1..498cbdd 100644
--- a/server/tserver/src/main/java/org/apache/accumulo/tserver/log/TabletServerLogger.java
+++ b/server/tserver/src/main/java/org/apache/accumulo/tserver/log/TabletServerLogger.java
@@ -319,7 +319,7 @@ public class TabletServerLogger {
               // Need to release
               KeyExtent extent = commitSession.getExtent();
               if (ReplicationConfigurationUtil.isEnabled(extent, tserver.getTableConfiguration(extent))) {
-                Status status = StatusUtil.fileCreated(System.currentTimeMillis());
+                Status status = StatusUtil.openWithUnknownLength(System.currentTimeMillis());
                 log.debug("Writing " + ProtobufUtil.toString(status) + " to metadata table for " + copy.getFileName());
                 // Got some new WALs, note this in the metadata table
                 ReplicationTableUtil.updateFiles(tserver, commitSession.getExtent(), copy.getFileName(), status);

;而

git log -- core/src/main | grep 31ee26b8ac41844f2a647a5d1484f47da731872a

不显示该提交。

我找不到任何答案!我将不胜感激任何见解!谢谢!

【问题讨论】:

  • 在最初的问题中,我提到了“子模块”,而我的意思是“子目录”。很抱歉造成混乱

标签: git logging github accumulo


【解决方案1】:

首先,apache/accumulo 中没有 .gitmodules 文件,所以我们根本不是在谈论 git submodules
相反,您可以考虑为子文件夹或子目录记录日志。不是子模块。

第二:

C:\Users\vonc\prog\git\accumulo>git show --name-only 31ee26b8a
commit 31ee26b8ac41844f2a647a5d1484f47da731872a
Author: Eric C. Newton <eric.newton@gmail.com>
Date:   Wed Mar 11 14:37:39 2015 -0400

    ACCUMULO-3423 fixed replication bugs with recent refactorings in StatusUtil

core/src/main/java/org/apache/accumulo/core/replication/StatusUtil.java
server/tserver/src/main/java/org/apache/accumulo/tserver/log/TabletServerLogger.java

这是指StatusUtil.java,现在在src/main/java/org/apache/accumulo/server/replication

换句话说,该文件在提交后被移动,而git log 默认只会列出重命名的文件

--follow 添加到git log

C:\Users\vonc\prog\git\accumulo>git log --graph --all --oneline --decorate  --follow -- core\src\main |grep 31ee26
| * | | | | | | | | | | | | | | | | | 31ee26b8a ACCUMULO-3423 fixed replication bugs with recent refactorings in StatusUtil

或者:

C:\Users\vonc\prog\git\accumulo>git log --follow -- core\src\main|grep 31ee26
commit 31ee26b8ac41844f2a647a5d1484f47da731872a

见“Why might git log not show history for a moved file, and what can I do about it?

【讨论】:

  • 感谢您的翔实解释!考虑到 git-log 文档, --follow 仅适用于单个文件。有什么方法可以使用 git follow 来获取目录中的所有文件?
  • @PooyanBehnamghader Git 不跟踪文件夹:文件夹的 log --follow 将包含对该文件夹中任何文件的更改的任何提交,即使这些文件之前已移动/重命名。所以从这个意义上说,使用文件夹是“使用 Git 跟踪目录中的所有文件”的一种方式。
  • 感谢@VonC 提供的信息。我在link 找到了以下信息“--follow 选项只能跟随一个文件。所以如果你能设法让它应用于一个目录,Git 会首先将目录变成一组文件,然后选择这些文件之一,然后只关注那个。”
  • @PooyanBehnamghader 是的,这与我在之前的评论中所说的相似
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-08-09
  • 2018-01-17
  • 2012-04-18
  • 2017-07-06
  • 2023-01-05
  • 1970-01-01
  • 2013-09-01
相关资源
最近更新 更多