Git

Git was created as a code version management tool.

File state

Repository database

Object

Git saves object in its object store. There are 3 types of object: blob, tree, and commit.

Index

Branch

Merge

The 3-way merge looks at the branch1 commit, the branch2 commit, and their nearest common ancestor commit to perform the merge.

Rebase

A rebase makes the history linear by recreating the branch1 commits of branch2. The original branch1 commits become orphaned and unreachable.

It is recommended to rebase only local commits that are not pushed yet to avoid merge conflict for others.

  1. Alice and Bob worked on a feature branch together.
  2. Alice created c2 for the feature and considered the feature done.
  3. Bob fetched c2 and planned to add something extra to the feature.
  4. Alice rebased c2 of the main branch c3 and created c2'.
  5. Bob created c4 and considered the feature done.
  6. Bob tried to rebase c4 of the main branch but failed due to duplicated changes caused by history diverge.
flowchart LR c0 --> c1 c1 --> c3 c3 --> c2' c1 --> c2 c2 --> c4 c4 -- cannot rebase --> c2'

Common commands

References

←Previous Next→