git 您如何在合并的更改之上重新设置当前分支的更改?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7297379/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you rebase the current branch's changes on top of changes being merged in?
提问by Jonathan M Davis
Okay. If I'm on a branch (say working
), and I want to merge in the changes from another branch (say master
), then I run the command git-merge master
while on the working
branch, and the changes get merged in without rebasing the history at all. If I run git-rebase master
, then the changes in master
are rebased to be put on the top of my working
branch. But what if I want to merge in the changes from master
but rebase my changes in working
to be on top? How do I do that? Can it be done?
好的。如果我在一个分支上(比如working
),并且我想合并来自另一个分支(比如master
)的更改,那么我git-merge master
在working
分支上运行该命令,并且更改被合并,而根本不会改变历史记录。如果我运行git-rebase master
,那么 中的更改master
将重新定位以放在我的working
分支的顶部。但是,如果我想合并来自的更改master
但将我的更改working
重新设置为最重要,该怎么办?我怎么做?可以做到吗?
I could run git-rebase working
on my master
branch to put my changes on top in the master
branch, but I'd like to be able to do that in my working
branch, and I have no idea how. The closest that I can think of doing is creating a new branch from master
and then rebase working
's changes on top of that, but then I'd have a new branch instead of altering the working
branch.
我可以git-rebase working
在我的master
分支上运行以将我的更改放在master
分支的顶部,但我希望能够在我的working
分支中做到这一点,但我不知道如何。我能想到的最接近的做法是从中创建一个新分支master
,然后working
在此基础上进行rebase的更改,但随后我会创建一个新分支,而不是更改该working
分支。
回答by hobbs
You've got what rebase
does backwards. git rebase master
does what you're asking for — takes the changes on the current branch (since its divergence from master) and replays them on top of master
, then sets the head of the current branch to be the head of that new history. It doesn'treplay the changes from master
on top of the current branch.
你有什么rebase
倒退。git rebase master
执行您的要求 - 获取当前分支上的更改(因为它与 master 不同)并在 之上重放它们master
,然后将当前分支的头部设置为新历史的头部。它不会从master
当前分支的顶部重播更改。
回答by VonC
Another way to look at it is to consider git rebase master
as:
另一种看待它的方法是考虑git rebase master
:
Rebase the current branch on top of
master
将当前分支重新建立在
master
Here , 'master
' is the upstreambranch, and that explain why, during a rebase, ours
and theirs
are reversed.
在这里,“ master
”是上游的分支,这解释了为什么,衍合过程中,ours
和theirs
反转。