Squashing (already pushed) commits on GitLab
Asked Answered
A

1

9

I have a merge request with 5 commits, all pushed to the branch on GitLab. I'd like to squash those 5 commits into 1 -- but there are intermediate commits to the repo by other people. E.g.,in git log, you might see

my5thcommitsha
my4thcommitsha
someoneelse'scommitsha
someoneelse'scommitsha
my3rdcommitsha
my2ndcommitsha
my1stcommitsha

I've already rebased my branch to the latest commit on the repo master branch I'm trying to merge into.

Now, I just want to squash my five commits so it's cleaner on GitLab -- how could I do this?

Does the "squash commits" checkbox next to the merge button create a single commit, or will there be two (1 commit containing my 5 commits, + a merge commit)?

Archfiend answered 19/2, 2021 at 5:28 Comment(1)
Well, I am not clear about what you are trying. I understand that the branch contains 7 commits, is that right? If it is right, you are trying to squash just your commits. Therefore, merge request will contain 3 commits. First is your squashed commits and 2 commits of someone else's. Do I understand you correctly?Pigg
S
1

The "squash commits" checkbox on a Merge Request will squash every single commit on a branch before it's merged into the target, so all 7 of the commits in your example will become one commit, and then it'll be merged. The one commit will have the commit sha and title of the squashed commits in its commit message.

The only way to squash all of your commits into a single commit is to also squash the other person's commits (but that might be ok, depends on your situation and the other person). The other option is to "fixup" your commits which is like a squash, but the original commits are effectively forgotten (they don't get mentioned in the final commit's message).

So, if you "fixed up" the last two commits, my5thcommitsha (and 4th), their changes would become part of "someoneelse'scommitsha2" changes. Then, you could fixup your 3rd and 2nd commits, so their changes are part of your 1st commit. With this, your history would look something like:

someoneelse's2ndcommitsha
someoneelse's1stcommitsha
my1stcommitsha
Schematic answered 21/2, 2021 at 23:34 Comment(1)
Note, that it's "the only option" using the Web UI, you can do much more via git cli.Lorin

© 2022 - 2024 — McMap. All rights reserved.