Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Popular Science - Git
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nvmnghia
Popular Science - Git
Commits
6e8d4ac3
Commit
6e8d4ac3
authored
Oct 28, 2019
by
nvmnghia
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
parent
f9db70a4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
6 deletions
+52
-6
README.md
README.md
+52
-6
No files found.
README.md
View file @
6e8d4ac3
...
@@ -27,6 +27,7 @@ Git advantage:
...
@@ -27,6 +27,7 @@ Git advantage:
-
Remote & local:
-
Remote & local:
-
Remote: hosted elsewhere
-
Remote: hosted elsewhere
-
Enable collaboration
-
Enable collaboration
-
Backup
-
Local: right here
-
Local: right here
-
`origin`
? Just default remote name
-
`origin`
? Just default remote name
-
`git remote rm/add/...`
-
`git remote rm/add/...`
...
@@ -47,6 +48,7 @@ Git advantage:
...
@@ -47,6 +48,7 @@ Git advantage:
-
Current snapshot
-
Current snapshot
-
Analogy: game checkpoint
-
Analogy: game checkpoint
-
ID: SHA-1
-
ID: SHA-1
-
Hash tree structure, not content
-
Internal:
-
Internal:
-
Save in blobs
-
Save in blobs
-
Another aspect of git:
**key-value DB**
!
-
Another aspect of git:
**key-value DB**
!
...
@@ -170,13 +172,14 @@ Git advantage:
...
@@ -170,13 +172,14 @@ Git advantage:
- `^` == `^1`
- `^` == `^1`
- `^3`: third parent
- `^3`: third parent
- Equal `~` if **no** merge commit along the path
- Equal `~` if **no** merge commit along the path
- Cause: DAG != tree
- Why 2 methods?
- DAG != tree
```mermaid
```mermaid
graph BT
graph BT
classDef master fill:#418a44;
classDef master fill:#418a44;
subgraph ref_from_HEAD
subgraph ref_
each_node_
from_HEAD
C1((C1));
C1((C1));
C2((C2)) -- "HEAD~4" --> C1;
C2((C2)) -- "HEAD~4" --> C1;
C3((C3)) -- "HEAD~^2~~" --> C1;
C3((C3)) -- "HEAD~^2~~" --> C1;
...
@@ -401,8 +404,9 @@ Git advantage:
...
@@ -401,8 +404,9 @@ Git advantage:
- Rebase: rewrite history (replay)
- Rebase: rewrite history (replay)
- Conflict is inevitable. Resolving is down to us.
- Conflict is inevitable. Resolving is down to us.
2.
Move commit around
2.
Move commit around
& Rewrite history
1.
Cherry-pick
1.
Cherry-pick
Manually copy commits then add it over `HEAD`
Manually copy commits then add it over `HEAD`
```bash
```bash
...
@@ -416,6 +420,7 @@ Git advantage:
...
@@ -416,6 +420,7 @@ Git advantage:
- Reorder commits
- Reorder commits
- Pick neccessary commits
- Pick neccessary commits
- Squash commits
- Squash commits
- Split commits
- The Golden Rule of Rebasing still applies:
- The Golden Rule of Rebasing still applies:
- NO rebase on PUBLIC
- NO rebase on PUBLIC
- Use rebase to cleanup before push
- Use rebase to cleanup before push
...
@@ -423,16 +428,54 @@ Git advantage:
...
@@ -423,16 +428,54 @@ Git advantage:
- Merge doesn't meant to *rewrite history* like rebase
- Merge doesn't meant to *rewrite history* like rebase
```bash
```bash
# Need to know the starting commit
git rebase -i HEAD~10
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
## Git Internal
1.
How git stores data (or what a commit actually is)
1.
How git stores data (or what a commit actually is)
-
Git stores, and each commit is, snapshot
-
Git stores, and each commit is, snapshot
-
Not diff
-
Not diff -> main difference between Git vs others
-
The main difference between Git & other VCS
-
Hidden cause: distributed vs centralized
-
Hidden cause: distributed vs centralized
-
Snapshot is large, how to minimize?
-
Snapshot is large, how to minimize?
-
Refer to unchanged file in previous snapshots
-
Refer to unchanged file in previous snapshots
...
@@ -440,3 +483,6 @@ Git advantage:
...
@@ -440,3 +483,6 @@ Git advantage:
-
Compress
-
Compress
2.
Hashed tree? Distributed? Sound familiar...
2.
Hashed tree? Distributed? Sound familiar...
Is git a blockchain???? No!
-
Git allow history rewrite
-
Git doesn't enforce verification (proof of work)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment