Git checkout --ours/theirs 在rebase与merge中的应用

实验

1.  master 分支 memo.txt 文件 内容master

1.1 切换到新分支 test-A 修改memo.txt 内容为  A

1.2 切换到新分支 test-B 修改memo.txt   内容为B

1.3 合并A  ==>  master

1.4 git chekcout test-B && git  rebase master

 git checkout --ours .  

结果如下 保留了master分支

 git checkout test-B && git merge master 

 git checkout --ours .  结果如下

 根据Git 官方文档的描述

Note that during git rebase and git pull --rebaseours and theirs may appear swapped; --ours gives the version from the branch the changes are rebased onto, while --theirs gives the version from the branch that holds your work that is being rebased.

This is because rebase is used in a workflow that treats the history at the remote as the shared canonical one, and treats the work done on the branch you are rebasing as the third-party work to be integrated, and you are temporarily assuming the role of the keeper of the canonical history during the rebase. As the keeper of the canonical history, you need to view the history from the remote as ours (i.e. "our shared canonical history"), while what you did on your side branch as theirs (i.e. "one contributor’s work on top of it").

注意在git rebase 和 git pull --rebase时,ours和theirs 是相反的

--ours 保留rebae目标分支(基准分支如master)改动的版本

--theris 保留被rebase分支(需要更新的分支 如test-B)的版本 

而在git merge中 基准分支是当前分支 即test-B 

--ours 保留合并基准分支(test-B)改动的版本

--theris 保留被合并分支(master)改动的版本

简单来说

--ours指代的是基准分支的版本,而在rebae和merge中 基准分支不一样,

在rebase中  基准分支是master 

在merge中基准分支是当前分支

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值