Stepan
Stepan

Reputation: 77

Conventional Commits type for merge conflicts

According to the docs https://www.conventionalcommits.org/en/v1.0.0/ or to another extendable source if I have a merge conflict what a commit type should I use?

Upvotes: 1

Views: 4509

Answers (1)

Tydax
Tydax

Reputation: 296

I cannot find all the sources that I had read on that topic, but it seems many Conventional Commit users do not use merge commits, and instead rebase their branch to fix conflicts before merging with --ff-only.

See Commit type according to convensional commit when resolving conflicts

I believe the approach would be that for each conflict, you would need to figure out to which of your commits the fix would belong. For example, if you have a commit that refactored some code and someone fixed a bug in the same area, you would squash that conflict fix into the refactor commit. The idea is to make the history look linear as if your branch introduces changes on top of the previous one, not parallelly.

The idea would be as follows:

  1. Make sure that your branches are up-to-date.
  2. Attempt rebasing against the branch you're merging: git checkout <my-branch>, then git rebase main (if merging into main)
  3. If there are conflicts, git rebase will stop at any commit that causes the conflict. After fixing the conflicts, you can either directly amend the current commit (if it is the one that makes the most sense to add changes to) via git commit --amend, or create new commits that you can link to existing ones with git commit --fixup <commit-hash>. These commits can later be squashed into the one it has been linked to. Then, git rebase --continue.
  4. (optional) When the rebase is complete, if you have any fixup commits, perform another rebase to squash any fixup commits with git rebase -i --autosquash main. This squashes the fixup commits into their “linked” ones.
  5. Finally, merge your branch: git checkout main and git merge --ff-only <my-branch>. The option means it will only merge if it can do so by fast-forwarding (just moving the branch tip to that commit without conflicts), which it should as your rebase took care of recreating the commits on top with conflicts handled.

Upvotes: 1

Related Questions