所有改动处理必需先提交本地进行处理,确认本地提交无误后才能进行推送,远端分支只允许:推送、拉取、获取。

graph TD;
    A[工作目录<br>本地改动区] -->|git add| B[暂存区];
    B -->|git commit| C[本地仓库<br>本地提交区];
    C -->|git push| D[远端仓库<br>远端提交区];
    C -->|git stash| E[贮藏区];
    E -->|git stash apply| A;

    %% 新增流程线
    Z[任意地方] -->|摘取文件到本地改动区| A;
    Z -->|另存文件覆盖本地| A;
    Z -->|另存文件覆盖提交| C;

    style A fill:#333,stroke:#333,stroke-width:2px;
    style B fill:#333,stroke:#333,stroke-width:2px;
    style C fill:#333,stroke:#333,stroke-width:2px;
    style D fill:#333,stroke:#333,stroke-width:2px;
    style E fill:#333,stroke:#333,stroke-width:2px;
    style Z fill:#333,stroke:#333,stroke-width:2px;

首先明确几个关键基础概念,除了常见的拉取、获取、推送外,还有

变基(Rebase)

摘取(Cherry-pick)

重置(Reset)

暂存(Stage)

贮藏(Stash)

合并(Merge)

本地提交(Local Commit)

本地分支(Local Branch)

为什么要使用变基拉取

image.png

image.png

如果把错误文件,提交到了远端,此时要还原提交,必须确保: