0

In a deployment pipeline I'm checking out master in a clean clone (which is the target) and then I merge the revision into it to update it.

git checkout master
git merge "${revision}"

As git has a pre-merge check it then tells in my scenario:

Already up-to-date.

when the revision was already merged.

How can I find out previous to the merge command, that this ("Already up-to-date") is the case, so that I can exit the pipeline early as there is nothing anymore to do?

hakre
  • 193,403
  • 52
  • 435
  • 836

4 Answers4

3
git merge-base --is-ancestor $revision master || git merge $revision
jthill
  • 55,082
  • 5
  • 77
  • 137
  • Thanks a lot, this one is straight forward, I'll put onto the run, let's see what breaks ^^ – hakre Dec 02 '19 at 15:35
  • Short answer: nothing. I needed an inverse test (if already merged, break the build with a message saying it's already merged), which was straight forward. Thanks a lot for the hint! – hakre Dec 05 '19 at 21:17
1

You can check output of below command

git log --oneline devlop..origin/master

this will show all the commits which are in origin/master but not in devlop branch.

if there is no output, then all changes are merged otherwise origin/master needs to be merged into devlop branch

Khem
  • 1,162
  • 8
  • 8
0

you can try using

git branch --merged

which will check list it for being merged already as explained on https://git-scm.com/book/en/v2/Git-Branching-Branch-Management

so you can checkout your revision as a temporary branch, check if it has been merged and remove it afterwards.

Jan Myszkier
  • 2,714
  • 1
  • 16
  • 23
  • The `${revision}` I have is not a branch name but the full hash ref. There is no branch for it. Is that a problem for git branch -- merged? – hakre Nov 27 '19 at 15:10
  • Just seeing your update, temp branch might be OKish, but can't this be checked for a revision as well? – hakre Nov 27 '19 at 15:11
  • no, as explained in my answer - you can create branch from revision and use it to do the check. – Jan Myszkier Nov 27 '19 at 15:12
  • what optionally comes to my mind is you can use git log as explained in https://stackoverflow.com/questions/14167335/find-commit-by-hash-sha-in-git and find your particular revision. just have in mind this will not work when your revision has other previous commits which is why I prefer --merged over searching the log – Jan Myszkier Nov 27 '19 at 15:13
  • Alright, I can follow so far what you suggest here, temporary branch name is required so I can keep being on the master branch. Let me fiddle with it. I think this needs some command lines. – hakre Nov 27 '19 at 15:26
0

you can use git diff ${revision} --name-status. If nothing is printed, then there are no differences between versions and no merge is needed.

Serge
  • 11,616
  • 3
  • 18
  • 28