What is a Merge in Git?
What is a Merge in Git? κ΄λ ¨
Merging is the process of combining the recent changes from several branches into a single new commit that will be on all those branches.
In a way, merging is the complement of branching in version control: a branch allows you to work simultaneously with others on a particular set of files, whereas a merge allows you to later combine separate work on branches that diverged from a common ancestor commit.
OK, let's take this bit by bit.
Remember that in Git, a branch is just a name pointing to a single commit. When we think about commits as being "on" a specific branch, they are actually reachable through the parent chain from the commit that the branch is pointing to.
That is, if you consider this commit graph:
You see the branch feature_1
, which points to a commit with the SHA-1 value of ba0d2
. Of course, as in other posts, I only write the first 5 digits of the SHA-1 value.
Notice that commit 54a9d
is also on this branch, as it is the parent commit of ba0d2
. So if you start from the pointer of feature_1
, you get to ba0d2
, which then points to 54a9d
.
When you merge with Git, you merge commits. Almost always, we merge two commits by referring to them with the branch names that point to them. Thus we say we "merge branches" β though under the hood, we actually merge commits.