56
you are viewing a single comment's thread
view the rest of the comments
[-] ValurianEwan@midwest.social 1 points 9 months ago

Handling conflicts in a merge will have them applied in a Merge commit (the only time a commit can have two parents).

Handling conflicts via a rebase will cascade across the replayed (copied) commits from which you're restarting onto the new base commit, individually. You will not have a Merge commit, each commit will have a single parent.

Reasons to perform a rebase. When your branch is to be temporary, when you want to be able to find a problem from commit to commit via a bisect, or when the total number of commits with expected conflicts is low.

Reasons to perform a merge. When you have two long running branches and you want to track the history of a single commit. For example when you have a release that you have tagged and you need a hotfix. You apply the fix to your release and then merge it into your mainline. So that you have historical reference of what was deployed when.

When is it fuzzy to use rebases vs merges. Working with others. You can rebase your local branch (and push your fast-forward merge), but not the shared branch. This changes the "history" (even when there are copies). Merges are most often the best tool when you are working with a shared branch.

I just brought up another merge, Fast-Forward merge. In git, branches are essentially a file with a commit in it. Every commit has a parent, with one exception, the first one. So long you have one commit, you can traverse the entire history up to that commit. So when your branch or remote has a commit that exists in the history of the target branch and you want to perform a merge it is called a Fast-Forward merge because you are simply updating the commit in that file to the commit that is newer. If there is a commit in a branch that does not exist one of the two branches, you will see an error and you will need to perform a Merge commit or a rebase.

There is also Squash merge, which collapses all commits into a single commit into a target branch. You will lose the history, but that may not be important (such as a Pull Request) where the history is not relevant (this is what we do at my workplace). When using a Squash merge, it will not matter if you use a Merge commit or a Rebase since it all just disappears (except the changes).

this post was submitted on 11 Feb 2024
56 points (93.8% liked)

Programming

17314 readers
321 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



founded 1 year ago
MODERATORS