How to get information about the source merge request in a squash commit?

Issue

I’m working on a CI pipeline in GitLab, for a project that has the following branching model:
enter image description here

Basically, once a merge request is created on a feature branch (commit 2), the CI pipeline will build artifacts with an automatic numbering system, which get uploaded to an artifact repository and deployed to a test environment. After code review and testing, we make more changes (commit 3) and the MR is approved. We then create a squash commit (because we like to do things that way).

Now, we want commit 4 (the squash commit on main) to get a git tag associating it with build 1.0.1+21, which is the last build number in the feature branch. But the squash commit doesn’t appear to have any link back to the feature branch; it just looks like an independent push to the main branch.

How can I get a tag on commit 4 that associates it with the right build artifact?

Solution

We then create a squash commit (because we like to do things that way) […] the squash commit doesn’t appear to have any link back to the feature branch

That is because you’re trying to have your cake and eat it too. It is by definition what squashing a to-be-merged branch into a single commit does: pretending the change has no history or parent branch, but suddenly appeared as a single commit.

Why do you want squash commits? If the answer contains the term "clean history", then you need to learn to rebase your feature branches to squash and reorder WIP commits instead.

I am not in favor of squashing entire features, because this will harm productivity in the long run, as I find commit messages to be part of your documentation and thought process. If you have other mechanisms in place for this, close to the source code, it may be defendable, but still, it causes more problems (merge conflicts and thrown away code being a major one) than to me it appears to solve.

As for your question: then you need to revise the process that creates these squash commits to include build tags made on the feature branch. Either delete the tag and create a new one, or include some phrasing in the commit message.

Answered By – CodeCaster

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published