Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitlab: why "squash" merge creates two commits?

Tags:

git

gitlab

To reproduce it:

  1. Create issue
  2. Open Merge Request (MR) from the issue
  3. Make changes with multiple commits
  4. Check "squash commits" and Merge the MR

Why on earth this creates TWO commits in history with exactly the same changes?

The commits titles:

  1. Merge branch '123-branch-name' into 'dev'
  2. Full Issue name

What is the point of that?

like image 509
stkvtflw Avatar asked May 02 '18 12:05

stkvtflw


1 Answers

Sounds like you create one commit containing your changes (commit Full Issue name) and a merge commit, merging changes from that commit into dev branch.

The merge commit is usually created for every merge request. This can be changed in Settings->Merge Request Settings by choosing e.g. Fast Forward Merge instad of Merge Commit. This will lead to only one commit on top of your current dev HEAD, which will only work if dev can be fast forwarded.

Checking squash commits will squash all commits in the feature branch you want to merge before merging it. Thus, if you had more than one commit in your feature branch, they would be squashed into one commit, which would be merged, creating a merge commit as you described (as long as your merge request settings are set to merge commit, see above).

The point of that is that you might want to see that changes were performed on a different branch. This is done by not fast forwarding the branch you merge into, but create a merge request instead. This displays that two lines of development were merged, while a fast forward merge (not creating a merge commit) would not.

like image 71
kowsky Avatar answered Sep 27 '22 19:09

kowsky