0

We have sometimes some merge requests on our Gitlab that has 30 commits just in one MR, and it makes the code-review really hard. Can we somehow "group" or "merge" all these 30 commits into one commit, even though this MR is already on Gitlab?

Is it doable? I hope that makes sense. Thanks

Ragnarsson
  • 1,715
  • 7
  • 41
  • 74
  • 1
    Yes. `git merge --squash` does exactly that. See [this question](https://stackoverflow.com/questions/5308816/how-to-use-git-merge-squash). – kowsky Nov 01 '17 at 08:33

2 Answers2

1

The pull request cannot be changed (it represent a tree you don't own), but you can checkout the branch that represents the pull request and merge a squash of all commits (git merge --squash).

Nevertheless, I would recommend not to do this: If commits were done separately, this probably mean that there were some incremental work done. You may think that, now job is done, the incremental view is useless, but this is exactly the contrary: if you experience a regression or if you find some awkward code in the future, you will probably try to find when and why the code was merged, and having small commits will help you to understand far more easily than a huge commit of 6000 lines saying "merge feature XXXX". BTW reviewing small patches if far more efficient than a huge one (I don't mean it is faster, I mean that you find more problems when modifications are smalls and the intention of the one who committed clear).

That say, many people use the squash technique, thus I guess it can be seen as "local good practices", after all, a team decides how it wants to work together.

OznOg
  • 4,440
  • 2
  • 26
  • 35
0

If you work with GitLab, you can use the Changes tab of the merge request and see the changes of all commits combined (i.e. the changes that would actually be applied to by the merge). Is that not what you want?

If you want to perform a squash, as suggested in the comments, there is no way (I know of) to do this directly in Gitlab. Thus, you would have to check out your branch locally, squash your commits (as explained in this question mentioned by @Hatik) and (force) push. The existing Merge Request will be updated automatically, containing only the one squashed commit.

EDIT: You do not have to squash all your changes in one commit. It is, of course, also possible to group your 30 commits in a smaller number of bigger commits.

kowsky
  • 12,647
  • 2
  • 28
  • 41