How do I find intersections between two git commits?

Namely, I am interested in finding files that were modified in both commits (or in two diffs if that is easier). Excuse me if it's simple, but I am still pretty new to git.


Update

After inputs from @PaulHicks ( git diff instead of git diff-tree ...thanks Paul) and to circumvent the error described here ie | sort | sort here's my updated answer:

comm -12 <(git diff --no-commit-id --name-only -r 3fe29472016343 | sort) <(git diff --no-commit-id --name-only -r 9fd796b1998bb7d5 | sort)

Old Answer I dont believe there is a command out of the box to do what you want to achieve. However, If you are on *nix platforms you can try this:

comm -12  <(git diff-tree --no-commit-id --name-only -r COMMIT1SHA1key) <(git diff-tree --no-commit-id --name-only -r COMMIT2SHA1key)

unfortunately I am typing from windows box :( ..hence cannot check this right away (I have to go home and try)

My idea here is git diff-tree will produce a list of files like here.

and this link shows how this comm -12 works on ls .

Weaving both may work is my guess


You can get the list of files changed in a single commit using git diff --name-only sha1^ sha1 . So you could do this in a script which takes two commit SHA-1s as parameters:

git diff --name-only $1^ $1 | sort > file1
git diff --name-only $2^ $2 | sort > file2
comm -12 file1 file2
rm file1 file2

Or if you're using bash on linux/unix, you can use the nifty trick from @Vikram's answer to avoid the temporary files:

comm -12 < (git diff --name-only $1^ $1) < (git diff --name-only $2^ $2)
链接地址: http://www.djcxy.com/p/26664.html

上一篇: 更改的文件列表

下一篇: 我如何找到两个git提交之间的交集?