git tricks (part I)
git tricks (part I)
- under the hood
- trees, references, commits, branches, merging
- git hacks
- gitdown demo
under the hood
git init
initialize a .git repository
git init demo
git repository
- a simple key value data store that stores:
- blobs, which are the most basic data type in Git. A blob is just a bunch of bytes; usually a binary representation of a file.
- tree objects, which are a bit like directories. Tree objects can contain pointers to blobs and other tree objects.
- commit objects, which point to a single tree object, and contain some metadata including the commit author and any parent commits.
- references, which are pointers to a single object (usually a commit or tag object).
.git/
-
.git/objects -
.git/refs
tree objects
- can be thought of as a directory
- contains a list of blobs (files) and other tree objects (sub-directories).
tree objects
README
src/
hello.c
tree objects
| tree 4da454.. | ||
|---|---|---|
| blob | 976165.. | README |
| tree | 81fc8b.. | src |
| tree 81fc8b.. | ||
|---|---|---|
| blob | 1febef.. | hello.c |
tree objects

commits
commit
- a pointer that contains a few pieces of important metadata.
-
the commit itself has a hash, which is built from the metadata that it contains:
- the hash of the tree at the time of commit
- the hash of parent commits
- author's info
- committer's info
- commit message
commit demo
references
references
-
.git/refs
- a file stored somewhere in .git/refs, containing the hash of a commit object.
references demo
branches
branches
branches are references
branches demo
merging
merging
the process of joining two branches together
merging demo
merging

back to demo
merging

back to demo
merging

git hacks
undoing things
-
Update a commit message
-
git commit --amend
-
-
Undo local changes
-
git reset / checkout
-
-
Undo pushed changes
-
git reset + git push --force
-
-
Undo last n commits
-
git reset HEAD~n
-
-
Undo part of a commit
-
git revert --no-commit
-
-
UNDO ANYTHING
-
git reflog + git checkout
-
branch diff
git show-branch
commit parts of a file
git add --patch
aliases

prettify git
- Configure colors to your .gitconfig
- Better git log
what are your favorite git hacks?
gitdown demo
next time?
- git features
- rebasing, cherry picking, tags
- git commands
- stash, bisect, fsck
git tricks
By Alexandra Qin
git tricks
- 332