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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 11:46:01  来源:igfitidea点击:

How do you rebase the current branch's changes on top of changes being merged in?

gitmergerebasegit-rebase

提问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 masterwhile on the workingbranch, and the changes get merged in without rebasing the history at all. If I run git-rebase master, then the changes in masterare rebased to be put on the top of my workingbranch. But what if I want to merge in the changes from masterbut rebase my changes in workingto be on top? How do I do that? Can it be done?

好的。如果我在一个分支上(比如working),并且我想合并来自另一个分支(比如master)的更改,那么我git-merge masterworking分支上运行该命令,并且更改被合并,而根本不会改变历史记录。如果我运行git-rebase master,那么 中的更改master将重新定位以放在我的working分支的顶部。但是,如果我想合并来自的更改master但将我的更改working重新设置为最重要,该怎么办?我怎么做?可以做到吗?

I could run git-rebase workingon my masterbranch to put my changes on top in the masterbranch, but I'd like to be able to do that in my workingbranch, and I have no idea how. The closest that I can think of doing is creating a new branch from masterand then rebase working's changes on top of that, but then I'd have a new branch instead of altering the workingbranch.

我可以git-rebase working在我的master分支上运行以将我的更改放在master分支的顶部,但我希望能够在我的working分支中做到这一点,但我不知道如何。我能想到的最接近的做法是从中创建一个新分支master,然后working在此基础上进行rebase的更改,但随后我会创建一个新分支,而不是更改该working分支。

回答by hobbs

You've got what rebasedoes backwards. git rebase masterdoes 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 masteron 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 masteras:

另一种看待它的方法是考虑git rebase master

Rebase the current branch on top ofmaster

将当前分支重新建立master

Here , 'master' is the upstreambranch, and that explain why, during a rebase, oursand theirsare reversed.

在这里,“ master”是上游的分支,这解释了为什么,衍合过程中,ourstheirs反转