Commit 6e8d4ac3 authored by nvmnghia's avatar nvmnghia

Update README.md

parent f9db70a4
......@@ -27,6 +27,7 @@ Git advantage:
- Remote & local:
- Remote: hosted elsewhere
- Enable collaboration
- Backup
- Local: right here
- `origin`? Just default remote name
- `git remote rm/add/...`
......@@ -47,6 +48,7 @@ Git advantage:
- Current snapshot
- Analogy: game checkpoint
- ID: SHA-1
- Hash tree structure, not content
- Internal:
- Save in blobs
- Another aspect of git: **key-value DB**!
......@@ -170,13 +172,14 @@ Git advantage:
- `^` == `^1`
- `^3`: third parent
- Equal `~` if **no** merge commit along the path
- Cause: DAG != tree
- Why 2 methods?
- DAG != tree
```mermaid
graph BT
classDef master fill:#418a44;
subgraph ref_from_HEAD
subgraph ref_each_node_from_HEAD
C1((C1));
C2((C2)) -- "HEAD~4" --> C1;
C3((C3)) -- "HEAD~^2~~" --> C1;
......@@ -401,8 +404,9 @@ Git advantage:
- Rebase: rewrite history (replay)
- Conflict is inevitable. Resolving is down to us.
2. Move commit around
2. Move commit around & Rewrite history
1. Cherry-pick
Manually copy commits then add it over `HEAD`
```bash
......@@ -416,6 +420,7 @@ Git advantage:
- Reorder commits
- Pick neccessary commits
- Squash commits
- Split commits
- The Golden Rule of Rebasing still applies:
- NO rebase on PUBLIC
- Use rebase to cleanup before push
......@@ -423,16 +428,54 @@ Git advantage:
- Merge doesn't meant to *rewrite history* like rebase
```bash
# Need to know the starting commit
git rebase -i HEAD~10
```
3. Change latest commit
- `git reset HEAD~1`
- `git commit -m amend`: Remove latest commit, stage all change, ready to commit
## Git remote
### Common flow
```bash
# Get remote repo to local 1st time
git clone repo
# Get remote changes to working directory
git pull remote branch
# ... is equivalent to
git fetch remote branch # Get remote changes
git merge remote/branch # Apply those changes
# Push changes to remote
git push remote branch
```
### Refspec & Tracking
1. `origin/master` vs `origin master`???
- `origin/master`: refspec = branch
- A local copy of `master` on `origin`
- Why no `git pull origin/master`, or `git pull origin origin/master`?
- The distinction is valid on local only
2. `origin/master` and `master`???
- `master` **tracks** `origin/master`
- Pull: changes are automatically merged to `master`
- Push: changes are automatically merged to `origin/master`
- Manually specify tracking:
```bash
git checkout -b notMaster origin/master
```
## Git Internal
1. How git stores data (or what a commit actually is)
- Git stores, and each commit is, snapshot
- Not diff
- The main difference between Git & other VCS
- Not diff -> main difference between Git vs others
- Hidden cause: distributed vs centralized
- Snapshot is large, how to minimize?
- Refer to unchanged file in previous snapshots
......@@ -440,3 +483,6 @@ Git advantage:
- Compress
2. Hashed tree? Distributed? Sound familiar...
Is git a blockchain???? No!
- Git allow history rewrite
- Git doesn't enforce verification (proof of work)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment