实验
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 --rebase
, ours 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中基准分支是当前分支