Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: git pull VS git fetch git rebase
我看到一些git项目建议您通过以下方式更新项目
git
git fetch; git rebase origin master
这样做有什么好处吗,与
git pull
从开源项目的角度来看github,因为无论如何你总是信任远程。
github
如果您没有对分支的本地副本进行任何更改,则两组命令将产生完全相同的历史记录。当您对当前分支副本进行本地提交时,差异就会发挥作用。
如果您git pull对远程所做的任何更改都将合并到您的本地分支中,并且您将在历史记录中进行合并提交。另一方面,如果您执行 fetch 后跟 rebase(或git pull --rebase),您的本地更改将在远程更改之上重播。这会导致更清晰的历史记录,因为您将有更少的合并提交使历史记录混乱。
git pull --rebase
由于新提交之前的历史记录与远程的历史记录相匹配,它通常也使您的更改更容易合并到上游。