user3719454
user3719454

Reputation: 1024

git: which files have been changed in both branches

I have 2 branches (A and B with common ancestor X), with multiple commits on each branch. I'd like to know the list of files which have been changed in both branches

A1 - A2 - A3 - ... - A

/

X

\

B1 - B2 - B3 - ... - B

So to display only files which can be found in both of these lists:

git diff X..A --name-only

git diff X..B --name-only

Upvotes: 2

Views: 612

Answers (2)

jthill
jthill

Reputation: 60275

( git diff --name-only A...B; git diff --name-only B...A ) | sort | uniq -d

is what you're looking for: files changed since the merge base on each, sorted, with only the duplicates listed.

Upvotes: 1

torek
torek

Reputation: 488183

Besides the two methods listed in the comments, consider using git ls-tree -r on the three commits in question. The output from ls-tree is already sorted, so comm works well here. If a file exists in all three commits with the same hash ID (and mode if you want to capture mode changes), you want to discard it; otherwise you want to include it in your final summary.

No matter which method you chose, you will need to write at least a little bit of code: use git merge-base (with --all if you want robust checking for a single merge base) to find commit X, then generate the file lists with either git diff or git ls-tree -r and do the filtering.

Upvotes: 1

Related Questions