git: fetch vs pull, merge vs rebase

本文详细解释了 Git 中 fetch 和 pull 操作的区别,包括它们如何更新本地仓库,以及 merge 和 rebase 的作用和区别。通过对比历史记录,直观地展示了这两种操作对本地仓库的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

fetch vs pull
fetch will download any changes from the remote branch, updating your repository data, but leaving your local branch unchanged.

pull will perform a fetch and additionally merge the changes into your local branch.

What’s the difference? pull updates you local branch with changes from the pulled branch. A fetch does not advance your local branch.

sync 同步 vs中的名词,在这里 同步=先拉取+后推送=先获取+在合并+最后推送
merge vs rebase

Given the following history:

      C---D---E local
     /
A---B---F---G remote

merge joins two development histories together. It does this by replaying the changes that occurred on your local branch after it diverged on top of the remote branch, and record the result in a new commit. This operation preserves the ancestry of each commit.

The effect of a merge will be:

      C---D---E local
     /         \
A---B---F---G---H remote

rebase will take commits that exist in your local branch and re-apply them on top of the remote branch. This operation re-writes the ancestors of your local commits.

The effect of a rebase will be:

              C'--D'--E' local
             /
A---B---F---G remote

What’s the difference? A merge does not change the ancestry of commits. A rebase rewrites the ancestry of your local commits.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值