git pull,git fetch和git rebase之间有什么区别?

6 浏览
0 Comments

git pull,git fetch和git rebase之间有什么区别?

这个问题已经有答案了: “ git pull”和“ git fetch”有什么区别?

< p> < code> git pull </ code>,< code> git fetch </ code>和< code> git rebase </ code>之间有什么区别?我感觉 pull 和 fetch 是一样的。</ p>

admin 更改状态以发布 2023年5月21日
0
0 Comments

获取(fetch):从远程更新本地但不与本地任何分支合并。

拉取(pull):更新本地并将更改与当前分支合并。

  • git fetch:从origin获取最新更改(不合并)

  • git pull = git fetch + git merge

  • 如果您将feature分支变基到master分支。执行git rebase master,则它将保留feature分支的commits/changes最前面。

    假设您的master分支中有两个提交(A-> C),而feature分支中有两个提交(B -> D)。

    假设您在feature分支中(git checkout feature)。现在,如果您合并master,则提交历史记录为:

    (previous commit) - A -- C       <- master
                      \        \
                        B -- D -- M   <- feature
    

    这里,Mnew-merge-commit-sha

    对于 rebase master, 提交历史记录如下(A -> C -> B' -> D')。

0