git pull、git fetch和git rebase有什么区别?

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

2
https://dev59.com/8XVC5IYBdhLWcg3wcgqd - jophab
1
我建议你阅读Pro Git。前三章涵盖了你日常所需的95%内容,包括你问题的答案。 - Code-Apprentice
git pull --rebase 相当于后面两个命令。 - Pockets
1个回答

5

Fetch: 从远程仓库更新本地代码,但不会和任何本地分支合并。

Pull: 从远程仓库更新本地代码,并将更改与当前分支合并。

  • git fetch: Get the latest changes from origin (no merge)

  • git pull = git fetch + git merge

  • If you rebase feature branch onto master branch. git rebase master, it would keep the feature branch commits/changes top.

    Say you have two commits in master branch (A -> C) and two commits in feature branch (B -> D).

    Assume you are in feature branch (git checkout feature). Now if you merge master then commit history:

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

    Here, M for new-merge-commit-sha.

    For rebase master, commit history: (A -> C -> B' -> D').


1
通常情况下,您会将“feature”变基到“master”,而不是相反。 - Code-Apprentice
1
git merge master 将会导致比你展示的更为复杂的提交历史。 - Code-Apprentice
只要正确,保持简单就好。就像你在“git merge”段落中所说的那样,提交历史是不正确的。 - Code-Apprentice
是的,这里我假设当前分支是 feature。执行 git checkout feature,然后执行 git rebase master。这样就会将 feature 分支变基到 master 分支上。 - Sajib Khan
请编辑您的答案以表明如此。 - Code-Apprentice
显示剩余9条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接