Reputation: 13
We have a git workflow where the latest stable version of the code is contained in our master branch. Continuing development and bugfixes are worked in separate branches and merged to a staging branch for testing prior to merging into master. Prior to merging a bugfix into the staging branch, developers are required to merge the staging branch into their bugfix branch to test their changes with any changes that occured since they branched off of master. Once all is well, the bugfix branch is merged into the staging branch. Our process dictates that we must provide a list of all files that changed as a result of a bugfix. We would like to avoid burdening our developers with this extra accounting work by forcing them to do things like tag their branch when they branch off of master and then generate the list before merging back to staging. So, what is the best way to determine the files that changed on the bugfix branch below after it has been merged into the staging branch? Essentially, we want the files that were changed starting with commit (1), but not any files that were changed as a result of merging the staging branch into the bugfix branch.
master (A)---(B)-----------------------(G)
\ /
staging \ (C)---(D)-----(E)-(F)
\ \ /
bugfix (1)---(2)---(3)---(4)
Upvotes: 1
Views: 396
Reputation: 496722
Assuming you didn't do anything evil in the merge commits (4) and (F), all you need is:
git diff --name-only commit-B commit-3
If you want to be really fancy, you could do this:
git diff --name-only $(git merge-base bugfix~1 master) bugfix~1
git merge-base
finds the most recent common ancestor of the two named commits, and bugfix~1
refers to the commit before bugfix
, i.e. commit (3).
If for some reason the staging branch was merged several times, you'd have to do a few such diffs and take the union, e.g.:
(git diff --name-only B 3; git diff --name-only 5 13) | sort -u
Upvotes: 2
Reputation: 13733
How about:
git checkout bugfix
git diff HEAD~1 master
This should give you the diff between the bugfix commit before the merge and master.
Upvotes: 0