Git on commits and branches
A commit is a snapshot, not a diff
- Each commit records every tracked file as it was at that moment.
- A file that did not change is not stored again. The commit reuses what is there.
- A diff is worked out when you ask, by comparing two snapshots.
Everything is stored under a hash of its content
- A blob holds one file's content. A tree lists file names and the blobs they point to.
- A commit points to one tree and to its parent commit, with author, date and message.
- Each ID is a hash of the content, so changing anything gives a different ID.
- IDs are 40 hex characters (SHA-1). A short prefix like f0e2a25 works in commands.
- Committree, parent, author, message
- Treeone folder: names and pointers
- Blobone file's content
History is a chain of parent links
- Every commit names its parent, so any commit leads back to the very first one.
- A merge commit has two parents. That is how two lines of work join.
- A commit's ID covers its parent's ID, so editing old history changes every later ID.
A branch is a pointer to one commit
- A branch is a name that holds one commit ID. Creating one copies no files.
- When you commit, the branch you are on moves forward to the new commit.
- Deleting a branch removes the name, not the commits.
$ git log --oneline --graph
* acb1237 (HEAD -> main) Merge branch 'search'
|\
| * 074ce38 (search) Add search box
* | f0e2a25 Fix cart total
|/
* f61dae4 Add cart pageHEAD is where you are now
- HEAD normally points to a branch: the one your next commit will move.
- git switch main points HEAD at main and updates your files to match.
- git switch --detach <commit> points HEAD at a commit, with no branch. Good for a look.
- Commits made while detached are on no branch. Keep them with git switch -c <name>.
Git 3.0 will change defaults, not the model
- As of December 2026 the latest release is Git 2.56. Git 3.0 is planned, not released.
- In 3.0, new repositories will use SHA-256 hashes instead of SHA-1.
- The first branch will be named main by default, as GitHub already does.
- There is no plan to drop SHA-1, so existing repositories keep working.