Comment 1

2 min

https://medium.com/mindorks/understanding-git-merge-git-rebase-88e2afd42671

git

comment 1

In Git, commit histories are managed differently by the git rebase and git merge commands, which affects how commits appear in the history.

  1. git merge:

    • When you use git merge, Git combines the two branches while keeping the history of both, by creating a specific merge commit. This means that all commits from both branches are visible in the history.
    • Benefit: The history stays complete and it is easy to see exactly where and when the branches diverged and merged. However, this can sometimes make the history more complex, especially if you have many intermediate commits.
  2. git rebase:

    • With git rebase, the commits of the current branch are “reapplied” on the target branch, which creates new commits corresponding to the old ones, but with new hashes (commit identifiers). This rewrites the history to give the impression that the commits were made directly on the target branch.
    • Benefit: The history is linear and easier to read, because it looks as if everything was developed in sequence without a distinct merge. However, the old commits are rewritten, and the original commit history is not preserved in the same way.

Summary:

  • git merge: Keeps the complete commit history of both branches, including the divergence and merge points.
  • git rebase: Rewrites the history by eliminating the divergence commits, creating a linear history without an explicit trace of when the branches diverged.

comment 2

It is really important to understand the key differences between Git Merge and Git Rebase if you want to be an excellent version-control manager! Git Merge is ideal for keeping the history of both branches and making sure everything is safely preserved. Git Rebase, on the other hand, is perfect for getting a clean, linear commit history. However, as with everything, there are a few things to watch, especially when you work on public branches. Following the golden rule of rebase can help you avoid tricky conflicts later. 📌 When you decide which one to use, just think about how your team works and the visibility you want to give to your branches! Never rebase commits that other people already pulled from the remote.