Git log of a specific branch already merged

43 Views Asked by At

I'm trying to update a documentation script in Python, as my coworkers and I have recently started working with GIT.

The point I'm at and stuck with now is trying to extract a list of the names of modified files in a branch via os.system(..). Is there any way to get a list with the names of the modified files in a branch if it has already been merged into another branch? Thanks in advance!

When I try to use a "git log --name-only --pretty=format: <feature_branch>", I get the feature_branch names of the files modified, but also the ones from the parent branch, which is the master_branch from which it was created, giving me not only the files we've been working with in the branch, but the whole history, which I'm not interested in.

I've also tried doing a "git log --name-only --pretty=format: <master_branch>..<feature_branch>", but the list comes up empty, and from what I've read, this could be because the feature_branch is already merged over the master_branch.

2

There are 2 best solutions below

2
jthill On BEST ANSWER

Is there any way to get a list with the names of the modified files in a branch if it has already been merged into another branch?

Find the merge, then git diff --name-only $merge^1...$merge^2. See the three-dot ... syntax in the git diff docs

2
Simon Yeh On

Extended from the answer of the post Finding a branch point with Git?

Use the magic bash command in the answer to find the <branch_point> commit hash

diff -u <(git rev-list --first-parent <feature_branch>) \
             <(git rev-list --first-parent master) | \
     sed -ne 's/^ //p' | head -1

Than use git diff --name-only <branch_point>..<feature_branch> to list changed files