Git diff working incorrect - to many changes

∥☆過路亽.° 提交于 2019-12-23 02:34:51

问题


           f1---f2                 - short term branch "feature1"
          /       \
      h--h--h---h--h1--h2-         - long term branch "hofix"
     /       \   \      \
    /         \   \      \
   m----m------m---m------m--      - long term branch "master"
                   |      |
                 1e1e1e 2f2f2f

I merge branches with 2 commits difference (15 file changed totaly). And ran:

$ git show --pretty="format:" --name-only 1e1e1e..2f2f2f

I receive more than 42 000 file changed from my project. Why?

Expected: i will show diff with f1,f2,h1,h2 commits

P.S. May be because "Merge branch 'origin/0411-hotfix'" commit?


回答1:


1e1e1e..2f2f2f means:

  • all commits that are reachable from 2f2f2f
  • excluding those that are reachable from 1e1e1e

(See "SPECIFYING RANGE" from gitrevisions)

If those SHA1s reference the two commits merged, you have:

    1e1e1e
      |
x--x--x
       \
        Z
       /
y--y--y
      |
    2f2f2f

That would give you all the files from all 'y' commits, which can potentially go as far as the very first commit, and that means you get all the files.

However, since git diff doesn't take a range of commits (as opposed to git show), you can try, as in "How to “git show” a merge commit with combined diff output":

git diff --name-only 1e1e1e..2f2f2f

Or simply use the merge SHA1 'Z', as in "List all modified files in git merge commit - even the fast forwarded":

git log -m -1 --name-only --pretty="format:" <Merge SHA>


来源:https://stackoverflow.com/questions/20093727/git-diff-working-incorrect-to-many-changes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!