[英]Git: How to pull from another repository without adding a merge commit
This is a project where multiple developers are working.这是一个由多个开发人员共同工作的项目。 Assume that all work is done on the master branch, and that there is a remote repo that has the following history today:
假设所有工作都在 master 分支上完成,并且今天有一个具有以下历史记录的远程仓库:
A --- B --- C
Today I went ahead and cloned this repository into one of my sandboxes (let's call this work_sb01
).今天我继续将这个存储
work_sb01
到我的一个沙箱中(我们称之为work_sb01
)。 I did some work, and have committed my changes locally (there could be just one commit or multiple commits).我做了一些工作,并在本地提交了我的更改(可能只有一次提交或多次提交)。 The Git history for this sandbox looks as shown below:
此沙箱的 Git 历史记录如下所示:
A --- B --- C --- X
Two days from today, I clone the same repository into another sandbox (let's call it work_sb02
).两天后,我将同一个存储库克隆到另一个沙箱中(我们称之为
work_sb02
)。 As expected, the repo HEAD
has moved, so the history might now look something like this:正如预期的那样,repo
HEAD
已经移动,因此历史现在可能看起来像这样:
A --- B --- C --- D --- E
I need to be able to pull the changes that I made in work_sb01
and bring them into work_sb02
.我需要能够提取我在
work_sb01
所做的更改并将它们带入work_sb02
。 I'm currently doing this with the following command:我目前正在使用以下命令执行此操作:
cd <path_to_work_sb02>
git pull <path_to_work_sb01> master
This gets the job done, but it creates a merge commit.这完成了工作,但它创建了一个合并提交。 I have now a requirement to avoid adding merge commits into the project Git log.
我现在需要避免将合并提交添加到项目 Git 日志中。 How can I pull the changes from
work_sb01
and make them the most recent commit in the history?如何从
work_sb01
提取更改并使它们成为历史记录中的最新提交? In other words, the local history for work_sb02
should look like the one shown below:换句话说,
work_sb02
的本地历史记录应如下所示:
A --- B --- C --- D --- E --- X
Here is the right way to do this from work_sb02:这是从 work_sb02 执行此操作的正确方法:
cd <path_to_work_sb02>
git remote add sb01 <path_to_work_sb01>
git fetch sb01
git checkout master
git rebase --onto master master sb01/master
If doing in path_to_work_sb02
a pull --rebase path_to_work_sb01
does not give you the right order, you could... consider doing the opposite:如果在
path_to_work_sb02
执行pull --rebase path_to_work_sb01
没有给你正确的顺序,你可以......考虑做相反的事情:
path_to_work_sb02
from path_to_work_sb01
path.path_to_work_sb01
路径中拉出 --rebase path_to_work_sb02
。path_to_work_sb01
as path_to_work_sb02
path_to_work_sb01
重命名为path_to_work_sb02
origin
URLorigin
URL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.