'git diff': Show only diff for files that exist in both commits

前端 未结 2 2013
悲哀的现实
悲哀的现实 2021-02-02 11:55

Is there a way to use git diff to get a diff between two commits, but only show the diff for the files that exist in both commits?

I have a branch I created

2条回答
  •  南旧
    南旧 (楼主)
    2021-02-02 12:21

    The following may do what you want:

    git diff --diff-filter=M commitA commitB
    

    The M option to --diff-filter says only to include files that appear to be modified between the two commits - ones that only exist in one branch or the other would be selected with A ("added") or D ("deleted").

    You can see which files would be selected with these letter codes by doing:

    git diff --name-status commitA commitB
    

    ... and there's more information about all of that in the git diff documentation.

提交回复
热议问题