How to concat commit messages with GitLab MR squash? - gitlab

I am using GitLab MR to push commits to my project.
I have a certain template in my commit message that I want to keep on my target branch (e.g. master).
for example:
[Notes]:
when pushing several commits in a single MR we get something like this:
Commit 1: [Notes]: Note1
Commit 2: Merge commit (the one I want to get rid of when squashing)
Commit 3: [Notes]: Note2
when squashing with GitLab MR the squashed commit message is the title of the MR, which prevents me to keep my original commits template.
Is there an option in GitLab setting to change the squashed message to be a concat of all commit messages? similar to interactive rebase in git.
wanted behavior:
Squashed Commit: [Notes]: Note1
Merge commit (the one I want to get rid of when squashing)
[Notes]: Note2
GitLab 14.9.2-ee

I managed to find what I was looking for, it is a GitLab feature introduced in the FREE edition since GitLab 14.6.
Open GitLab website -> Settings -> General -> Merge requests -> Squash commit message template.
Then in the textbox add the following flag:
%{all_commits}
The commit messages are shown in the squash message according to their chronological order.

I do have this checkbox (see attached image) in my merge request enabling me to change the Merge Commit Message but I am using: 15.2.1-ee I'm not sure on what version this got introduced. I think there was a similar functionality in previous versions.

Related

How to check current branch head compare to default branch in GitLab

GitHub web shows where is the selected branch compare to default branch. For example here dev is the default branch and I have selected qa branch. It shows that qa branch is 1 commit behind dev.
Does GitLab have the same kind functionality in UI.?
Sure!
Navigate to Repositories > Branches, the list of branches has an indicator (before status icon and Merge Request button)
once you hover above, it explains "N commits behind ... M commits ahead"
Clicking on Compare brings detailed diff in commits and files

Gitlab: How to setup squash on merge?

I want to setup the squash on merge policy in GitLab. This gif showcases exactly what I would like to have:
Merge Strategies
I have set the GitLab merge method to "Fast-forward merge" and the squash commits policy is set to mandatory when merging.
Once merge is done, the git log of the main branch is exactly like I want it. The feature branch commits were squashed and the whole feature appears as one commit in the git log.
Here's the problem:
The squashed commit that is now the head of the main branch has the timestamp of the last commit in the feature branch. I would expect it to be the timestamp of when the fast-forward merge happened (squash). Is there a way to set it up in GitLab?
The merge timestamp is important for me since I need to know when the feature made its way into the main branch. However, I want to keep the commit history streamlined and straightforward, so the default option with an additional merge commit for every merge is something I want to avoid.

Show all changes made between a range of commits in GitLab UI

Say I have 10 commits in my merge request. I'd like to see all changes made between the first commit and the second to last commit. How can I see this in the GitLab UI?
You can view 'Changes' tab to view all changes in merge request
You can also click on individual commits to view what is changed in that particular commit
You can check diff between two arbitrary commits using https://gitlab.com/$USER/$REPO/compare?from=$SHA1&to=$SHA2
Reference:
https://stackoverflow.com/a/50070145/2073920
Use format
https://gitlab.com/$USER/$REPOSITORY/compare?from=commit_hashtag1&to=commit_hashtag2
For example, You use URL like this
https://gitlab.com/Donhu/java_examples/compare?from=7f844e6b&to=1ff5c89c

View Git history before a specific commit ID in the current branch

I'd like some Git log command to list out the commits before some specific commit ID/hash in the current working branch.
E.g. Something like
git log --before <commit id>
But I haven't been able to find what the correct command to do this is.
Just give the commit hash as the ref to explore via log
git log <commitHash>
and it will output all history from that point, backwards, until initial commit.
Alternatively, if you need to exclude this specific commit itself, then refer to its parent with
git log <commitHash>^
Sidenote about your mention of "in the current working branch"
Branches are technically irrelevant here to tree traversal logic. This won't limit output to what's "in" the branch, largely because the common metaphor is quite bad : commits are just not "on" branches. Branches are to be seen as soft (and disposable) shortcuts to designate one commit in the tree.

How to do a code review for many commits in gitlab?

What is the easiest/best way to review a merge request in gitlab for a branch that has many commits?
Is there a “unified” view I can use somehow or is the only option to click on the “Changes” tab and go through each individual commits one by one?
You do not need to go through each invidividual commit one by one.
You should click on the Merge Request's "Changes" tab, instead of the "Changes" tab of individual commits, so you see the changes between the latest version and the branch you want to merge into, e.g. with Master:
This way, you will see all changes that are proposed within the merge request and you can review them all at once.

Resources