【问题标题】:Git diff shows too many filesGit diff 显示文件太多
【发布时间】:2016-12-05 18:04:55
【问题描述】:

在向 QA 创建 TFS 拉取请求时,当它说有 300 个文件被修改时我感到很震惊,尽管预计不会超过 20 个。

当我运行git log --oneline --graph QA..MyCode 时,它返回 8 个提交(与 TFS 中显示的相同):

* 4db6392 Message Hidden (3 files)
* 9fdda73 Message Hidden (4 files)
*   64bbab8 Message Hidden (3 files)
|\
| * 1ca059d Merge master -> MyCode (13 files)
| * 3200fe0 Message Hidden (1 file)
| * e27653c Message Hidden (1 file)
| * cd57d2f Message Hidden (1 file)
* e2afeef Message Hidden (9 files)

括号中的文件数量是使用git show --name-only *SHA* 找到的,在许多情况下,同一个文件在不同的提交上被更改。

但是,当我运行 git diff --name-only QA..MyCode 时,它会列出 304 个文件。

最后一个 e2afeef 之前的提交是 41e68bb,如果我按预期运行git log QA..41e68bb,它什么也不返回。但是运行 git diff --name-only QA..41e68bb 会返回大约 680 个文件。

我很困惑!谁能解释发生了什么,或者指出我如何进一步调查的正确方向?

【问题讨论】:

    标签: git tfs git-merge git-diff git-log


    【解决方案1】:

    <commit>..<commit>diff 的含义与log 的含义不同(rebase 等)。来自git diff --help

       Comparing branches
    
               $ git diff topic master    (1)
               $ git diff topic..master   (2)
               $ git diff topic...master  (3)
    
           1. Changes between the tips of the topic and the master branches.
           2. Same as above.
           3. Changes that occurred on the master branch since when the topic branch was started off it.
    

    我认为您需要的是示例 (3) -> git diff --name-only QA...MyCode
    更新
    运行git merge-base --all QA MyCode 给出了 2 sha1 - 交叉合并的明显标志。

    --o--p--q--r--s   <-QA
       \/
       /\
    --A--B--C--D--E   <-MyCode
    

    最好重写 MyCode 的历史(我想这是一个私人分支,没有人基于它工作)

    --o--p--q--r--s   <-QA
       \/
       /\
    --A--B--C--D--E   <-MyCode-backup
       \
        \b'-c'-d'-e'  <-MyCode
    

    图链接o-B会丢失,但不会丢失链B-E的内容。

    git checkout MyCode
    git branch MyCodeBackup  #this branch will keep original B-E reachable
    gir rebase --no-ff A  #b'-e' recreation
    git diff MyCode MyCodeBackup #for test - should give nothing - content equal
    git diff QA...MyCode #supposedly of sane size
    

    您可以随时git reset --hard MyCodeBackup 恢复原状。

    【讨论】:

    • 运行 "git diff --name-only QA...MyCode" 仍然返回大量文件,其中 312 个。
    • 你可以尝试做的是 - 找到最好的共同祖先 git merge-base --all QA MyCode。据说应该是41e68bb。然后检查分支如何与共同祖先分歧:git diff --shortstat ancestor..QAgit diff --shortstat ancestor..MyCode。也许它会清除情况
    • 有两个基础(在我的提交列表中都没有显示),我想有一个跨越许多提交的交叉合并。这是导致误报文件数量的原因吗?
    • 我只是在 diff 上尝试了不同的 diff-algorithm 参数,似乎没有任何改变。
    猜你喜欢
    • 2019-09-24
    • 2013-01-11
    • 2017-11-22
    • 2011-07-12
    • 2014-04-18
    • 1970-01-01
    • 1970-01-01
    • 2015-06-08
    • 2013-04-01
    相关资源
    最近更新 更多