Gitlab: How to setup squash on merge? - gitlab

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.

Related

How to concat commit messages with GitLab MR squash?

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.

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.

Perforce -Keep working on the project while the code is under review

I am a git person. In git, after I finishing a little feature, I will submit the branch to review and start a new branch to work on new features.
For example, I had submitted a code recview for feature A, and it is still under review. At this time, I want to start working on feature B, assuming feature A's code will be merged in the near future. In Git, typically I just create a new branch to work on the new feature, if there is some problem with feature A I can easily switch back to branch A to fix it and merge the fixed version to my new feature branch.
How's it achieved in perforce? Should I copy the whole code somewhere as a way to manage branch myself?
You can do this in Perforce exactly the same way you'd do it in Git, if you like -- create your feature B branch and work on feature B there. If you need to make changes to your feature A branch, those can be merged back to your mainline and/or your feature B branch.
If you do your code reviews as shelves, you can have any number of them in development at a time; a shelved change is effectively "rebased" onto submitted changes when you sync+resolve.
FWIW, usually the way I've done reviews in Perforce is to make my changes on my own development branch, set up the merge to the mainline, and then shelve that for review. That way I can continue work on my development branch uninterrupted, I don't need to create a new branch, and if there's a fix needed to my merge-in-progress I can just amend the shelved change (either by submitting the fix to my branch and adding it to the merge, or making the edit as part of the merge operation); it also has the benefit of making conflict resolution (if any) part of the change under review.

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