git pull与git pull --rebase
aliases: []
tags: [git]
link:
date: 2022-08-30
git pull --rebase
在 push 代码时,会提示使用 git pull 命令,也就是拉取远端代码,更新我们的仓库,那么为什么又要加个 --rebase 命令呢?下面来说说这个问题,先从这两命令开始。
git pull = git fetch + git merge FETCH_HEAD
git pull --rebase = git fetch + git rebase FETCH_HEAD
二者的区别是,在 fetch 之后的操作不同,merge 与 rebase 的不同。
假设当前 master 的提交如下:

如果是你或者你的同事在 cid2 点,开发进度是 cid20(或者突然撇出一个分支,假设是 tmp 分支),此时要把 cid20 提交到 master

在 master 执行 git merge tmp, 然后会得到如下结果:

那么来看看 git rebase, 在 master 执行 git rebase tmp,操作之后的分支如下:

二者对比可知,rebase 没有产生新的节点,使用 rebase 的 git 演进路线 (提交树) 是一直向前的,这样在版本回退时也很容易,用 merge 的 git 路线是跳跃的,如果版本回退你也找不到自己想要的版本,如果在 merge 时出现了冲突那就麻烦了,当前 merge 就不能继续进行下去,需要手动修改冲突内容后,add,commit, push. 而 rebase 操作的话,会中断 rebase, 进入rebasing状态,这时我们需要解决冲突后执行git add,然后执行git rebase --continue直至冲突解决完毕,自动退出rebasing状态,再 push.
想要更好的提交树,建议使用 rebase 操作会更好一点,这样可以线性的看到每一次提交,并且没有增加提交节点。不过也有些项目,不建议使用 rebase, 这就得看公司与项目的规定。
等效命令
- git stash先暂存代码
- git pull拉到最新
- git add并commit
总结
在提交代码前如果无法拉取最新代码,除了可以使用git stash暂存,还可以使用git commit配合git pull --rebase提交代码,最终达到减少代码”不良记录“的目的
参考文章
git pull与git pull --rebase的更多相关文章
- Difference between git pull and git pull --rebase
个人博客地址: http://www.iwangzheng.com/ 推荐一本非常好的书 :<Pro Git> http://iissnan.com/progit/ 构造干净的 Git ...
- 对比git pull和git pull --rebase
1.使用下面的关系区别这两个操作:git pull = git fetch + git mergegit pull --rebase = git fetch + git rebase 2 一.基本 g ...
- 简单对比git pull和git pull --rebase的使用
使用下面的关系区别这两个操作:git pull = git fetch + git mergegit pull --rebase = git fetch + git rebase 现在来看看git m ...
- 【Git】git pull和git pull --rebase的使用
git pull = git fetch + git mergegit pull --rebase = git fetch + git rebase 现在来看看git merge和git rebase ...
- git fetch 、git pull 与 git pull --rebase
1. git fetch 与 git pull 都是从远程拉取代码到本地,git fetch只是拉取到本地,git pull不仅拉取到本地还merge到本地分支中.所以git pull是git fet ...
- git pull和git pull --rebase的使用
使用下面的关系区别这两个操作: git pull = git fetch + git merge git pull --rebase = git fetch + git rebase 现在来看看git ...
- 差异:git clone , git fetch, git pull和git rebase
随笔 - 96 文章 - 1 评论 - 6 Git Pull据我所知,当你使用git pull时,它将会获取远程服务器(你请求的,无论什么分支)上的代码,并且立即合并到你的本地厂库,Pull是 ...
- Git 协作:Fetch Pull Push Branch Remote Rebase Cherry-pick相关
前言 学习git的时候,我们首先学习的是最常用的,自己独立开发Software时用的命令: git init //初始化git仓库 git add <file_name> //将文件添加到 ...
- git pull、git fetch、git merge、git rebase的区别
一.git pull与git fetch区别 1.两者的区别 两者都是更新远程仓库代码到本地. git fetch相当于是从远程获取最新版本到本地,不会自动merge. 只是将远程仓库最新 ...
随机推荐
- B2. Wonderful Coloring - 2
链接:Problem - 1551B2 - Codeforces 题意:有m个颜色,要求每种颜色内的数字各不相同,问,颜色的最大长度多少. 题解: 判断每个数字的个数,如果大于m,那么最大长度就加一 ...
- Helm安装ingress-nginx-4.2.3
Application version 1.3.0 Chart version 4.2.3 获取chart包 helm fetch ingress-nginx/ingress-nginx --vers ...
- Python数据科学手册-Pandas:数据取值与选择
Numpy数组取值 切片[:,1:5], 掩码操作arr[arr>0], 花哨的索引 arr[0, [1,5]],Pandas的操作类似 Series数据选择方法 Series对象与一维Nump ...
- C++ "链链"不忘@必有回响之双向链表
C++ "链链"不忘@必有回响之双向链表 1. 前言 写过一篇与单链表相关的博文(https://blog.51cto.com/gkcode/5681771),实际应用中,双向循环 ...
- KubeOperator界面,集群详情中的存储,存储提供商
点击"添加",假设选择的类型是rook-ceph,表示的是在这个k8s集群里创建rook-ceph集群,而不是显示已经存在的集群 意味着可以使用这种办法在k8s集群里创建rook- ...
- Logstash:input plugin 介绍
- Keepalived设置master故障恢复后不重新抢回VIP
(1).master配置 ! Configuration File for keepalived global_defs { router_id lb01 } vrrp_script check_ng ...
- gitlab备份和恢复
备份 生产环境下,备份是必需的.需要备份的文件有:配置文件和数据文件. 备份配置文件 配置文件包含密码等敏感信息,不要和数据文件放在一起. sh -c 'umask 0077; tar -cf $(d ...
- Node.js躬行记(23)——Worker threads
Node.js 官方提供了 Cluster 和 Child process 创建子进程,通过 Worker threads 模块创建子线程.但前者无法共享内存,通信必须使用 JSON 格式,有一定的局 ...
- Monaco Editor 中的 Keybinding 机制
一.前言 前段时间碰到了一个 Keybinding 相关的问题,于是探究了一番,首先大家可能会有两个问题:Monaco Editor 是啥?Keybinding 又是啥? Monaco Editor: ...