Saturday, November 11, 2023

Looker and GitLab

 Looker is a category-defining enterprise analytical tool from Google Cloud and Git is the world-class versioning tool. As Looker provides IDE to develop content using LookML language, GitHub, GitLab are web based platforms that uses Git to version the code and also provide advanced collaboration and DevOps features.


Recently I ran into an issue where I was successfully able to migrate code from my personal GitLab branch to the master branch (dev environment). But when I tried to merge my changes with the test branch for UAT, I got error that said "The source branch is 2 commits behind the target branch". I could not understand it as the test branch is protected and no one could modify it directly. 


With bit of learning Git and the way merging and squashing works I realised the cause behind it. The first time I tried to merge my changes from master (dev) to test branch (UAT), it went all fine. While creating that merge request I checked the option "Squash all commits" in GitLab. This caused all the different commits in master branch to be combined in a single commit with new hash value. Then the second time I tried to create a merge request I chose to not select the squash all commits option. This made GitLab to compare the master and test branch and check that the commits with same hash exists in both the places.

Ideally I would not need all the commits of master branch in the test branch, so as to keep it relatively clean. But I would want all the commits to exist in the master (dev) ranch. So, while creating the merge request to merge code from my personal branch to master, I need to ensure that I do not check the squash commit. But when I create merge request to merge code from master to test, then I need to select the squash option so that all the commits of master goes in to test as a single commit with new commit and hash value. But the challenge I will face is that it works for the first merge into test but the in the next merge, GitLab will not allow merging as the hash value between master and test will not match.



The solution I got working was to revert the earlier successful merge into test and then create a new merge request. This time I did not select squash all commits and though it showed the message "source is 2 commits behind the target" (which is the first successful merge with new has value and second merge for reverting the first merge with its own hash value). This approach will cause the test branch to contain all the commits from master branch but will work just fine.

#Looker #LookML #Git #Gitlab #Merge




No comments:

Post a Comment