git 各区的关系
- remote repository 远程版本库,一般存在服务器端。
- repository 本地版本库。
- staging area 暂时存区,也叫index。
- working directory 工作区。
- stash 储藏区。
各区示意图
+----------------------+ +----------------------+
| repository | | remote repository |
+----------------------+ +----------------------+
+----------------------+
| staging area |
+----------------------+
+----------------------+
| working directory |
+----------------------+
+----------------------+
| stash |
+----------------------+
git reset
+-------- +----------------------+
| | repository |
| +---- +----------------------+
| |
| git reset --soft
| |
| +---> +----------------------+
git reset --hard | staging area |
+-------> +----------------------+
|
|
|
+-------> +----------------------+
| working directory |
+----------------------+
git checkout
+-------- +----------------------+
| | repository |
| +----------------------+
git checkout CX file
|
|
|-------> +----------------------+
| | staging area |
| +---- +----------------------+
| |
| git checkout file
| |
| +---> +----------------------+
| | working directory |
+-------> +----------------------+
git commit / add
+----------------------+ <-------+
| repository | |
+----------------------+ <---+ |
| |
git commit -m |
| |
+----------------------+ ----+ |
| staging area | | git commit -a -m
+----------------------+ <---+ |
| |
git add | |
| |
+----------------------+ ----+ |
| working directory | |
+----------------------+ --------+
git stash
+----------------------+
| staging area |
+----------------------+ <-------+
|
|
|
+----------------------+ <-------+ git stash pop --index
| working directory | | git stash apply x --index
+---- +----------------------+ <---+ |
| git stash pop | |
| git stash git stash apply x |
| | |
+---> +----------------------+ ----+ |
| stash | |
+----------------------+ --------+
git pull / fetch / push
git pull /git fetch
+--------+
| |
V |
+----------------------+ +----------------------+
| repository | | remote repository |
+----------------------+ +----------------------+
| ^
| |
+--------+
git push