1

We use git to store source code and use master/release/develop as main branches. Normally we create new branch to add new feature and then merge to develop and release. But when production needs immediate fix, we change code directly in prod and create hotfix branch which is then merged with all 3 main branches.

I would like to compare these uncommitted changes in prod with git, especially with release and develop branches which will become new master one day - just to be sure that no one forgot to commit some change from prod.

Manually I can use git diff and compare whether it was merged with release branch but it's not fast enough and it's manual.

Can you help me how to compare uncommitted changes with git content?

Sourav Ghosh
  • 133,132
  • 16
  • 183
  • 261
Rasto
  • 11
  • 1

1 Answers1

0

Anything which you do manual you can convert to script

For example if you wish to compare 3 branches:

git diff <b1> <b2> <b3>

If you want you can also generate patch files between the branches and again wrap it with a script. Your script than can become your alias

# extract all commits as patches, each one inits own patch file
git format-patch <b1> <b2>

# generate a single patch per changes
git diff <b1> <b2> > patch.txt

Once you have your scripts you can use git hooks or CI/CD process which will be triggered upon merge and will generate the patched for you.

Here is a sample script:

#!/bin/sh

# loop on the desired branches (you can pass them as arguments as well)
for branch in b1 b2
do
    # generate the patch file and write it to a file with the branch name
    git diff master..$branch > $branch.txt
done;
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • So I can use `git fetch` and `git diff origin/release` but then I see also other changes from release which were not hotfixed in prod - the diff result is then even larger. Can I somehow limit comparison to local changes? – Rasto Dec 14 '18 at 10:51