git 各区的关系

git 各区的关系

  • remote repository 远程版本库,一般存在服务器端。
  • repository 本地版本库。
  • staging area 暂时存区,也叫index。
  • working directory 工作区。
  • stash 储藏区。

各区示意图

                        +----------------------+        +----------------------+
                        |      repository      |        |   remote repository  |
                        +----------------------+        +----------------------+

                        +----------------------+
                        |     staging area     |
                        +----------------------+

                        +----------------------+
                        |   working directory  |
                        +----------------------+

                        +----------------------+
                        |       stash          |
                        +----------------------+

下文中:

  • bxx 表示branch
  • cxx 表示commit
  • fxx 表示file

git reset

            +--------   +----------------------+
            |           |      repository      |
            |   +----   +----------------------+
            |   |
            | git reset --soft
            |   |
            |   +--->   +----------------------+
    git reset --hard    |     staging area     |
            +------->   +----------------------+
            |
            |
            |
            +------->   +----------------------+
                        |   working directory  |
                        +----------------------+

git checkout

            +--------   +----------------------+
            |           |      repository      |
            |           +----------------------+
    git checkout cxx fxx
            |
            |
            |------->   +----------------------+
            |           |     staging area     |
            |   +----   +----------------------+
            |   |
            | git checkout fxx
            |   |
            |   +--->   +----------------------+
            |           |   working directory  |
            +------->   +----------------------+

git commit / add

                        +----------------------+   <-------+
                        |      repository      |           |
                        +----------------------+   <---+   |
                                                       |   |
                                            git commit |   |
                                                       |   |
                        +----------------------+   ----+   |
                        |     staging area     |           | git commit -a
                        +----------------------+   <---+   |
                                                       |   |
                                              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 fetch / push

                                               git fetch
                                               +--------+
                                               |        |
                                               V        | 

                        +----------------------+        +----------------------+
                        |      repository      |        |   remote repository  |
                        +----------------------+        +----------------------+

                                               |        ^
                                               |        |
                                               +--------+
                                                git push
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值