git rebase origin/develop 与 git rebase develop
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42617683/
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
git rebase origin/develop vs git rebase develop
提问by Polymerase
Let's assume the current branch is MyFeatureX. And the local develop
branch is up-to-date with origin. Would the two statements below be equivalent?
What is the recommended syntax?
让我们假设当前分支是 MyFeatureX。并且本地develop
分支是最新的起源。下面的两个语句是等价的吗?推荐的语法是什么?
git rebase origin/develop
git rebase develop
Please note: This is notthe same question as git rebase origin vs.git rebase origin/master
请注意:这与git rebase origin vs.git rebase origin/master不是同一个问题
回答by Andy Ray
Your local branch develop
tracksorigin/develop
and they might not always have the same commits in them.
您的本地分支develop
跟踪origin/develop
并且它们可能并不总是具有相同的提交。
$ cat ~/.git/config
[remote "origin"]
url = [email protected]/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
This means we have a "remote" (a repository living somewhere else) arbitrarily named "origin".
这意味着我们有一个任意命名为“origin”的“远程”(位于其他地方的存储库)。
Your local develop
branch is tracking the branch from that remote repository, and there's a local reference to that data called origin/develop
. For the most part, we consider these two things to always contain the same commits. However, you need to explicitly update your local develop
branch to get the latest data from origin. This is mostly commonly done with a pull:
您的本地develop
分支正在跟踪该远程存储库中的分支,并且对该数据的本地引用称为origin/develop
. 在大多数情况下,我们认为这两件事总是包含相同的提交。但是,您需要显式更新本地develop
分支以从源获取最新数据。这通常是通过拉动来完成的:
$ git status
on branch develop
$ git pull
...pulls latest changes from origin
However, a git pull
actually does two steps, a fetch
and a merge
. The first step it does under the hood is fetch all the latest commits from origin, which you can do with
然而, agit pull
实际上做了两个步骤, afetch
和 a merge
。它在后台执行的第一步是从源中获取所有最新提交,您可以使用它
git fetch origin
This will update the branch origin/develop
, but not your local branch develop
.
这将更新分支origin/develop
,但不会更新您的本地分支develop
。
The newest commits are hidden "behind the scenes" in your local .git directory, which you can reference from the branch named "origin/develop".
最新的提交隐藏在您本地 .git 目录中的“幕后”,您可以从名为“origin/develop”的分支中引用该目录。
After a fetch, to actually make your local branch origin
, you would have to do git merge origin/develop
. This technically isn't a merge, it will be a "fast forward," meaning git is smart enough to make your local origin
branch match origin/develop
without actually merging anything. For this reason and others, merges freak me out in git.
获取后,要实际创建本地分支origin
,您必须执行git merge origin/develop
. 从技术上讲,这不是合并,而是“快进”,这意味着 git 足够聪明,可以在不实际合并任何内容的情况下使您的本地origin
分支匹配origin/develop
。出于这个原因和其他原因,合并让我在 git 中感到害怕。
So if you rebase off of develop
, there's a chance it will be out of date (older) than origin/develop
.
所以,如果你的衍合过develop
,有一个机会,这将是日(以上)比了origin/develop
。
I personally do this workflow before rebasing:
我个人在变基之前执行此工作流程:
git fetch --all
git rebase origin/branchname
This means that I can pull all data down without having to think too much about what branch I'm on, and rebase off the latest code from the remote repository. Later, on the develop
branch, a simple git pull
will make sure you're up to date.
这意味着我可以提取所有数据而不必过多考虑我所在的分支,并从远程存储库中重新设置最新代码。稍后,在develop
分支上,一个简单的方法git pull
将确保您是最新的。
回答by Penguin Brian
If develop
points to the same commit as origin/develop
then the two commands are exactly the same. I would tend to use origin/develop
in case I had forgotten to update my local develop
(assuming this branch is eventually going to be pushed to origin/develop
).
如果develop
指向相同的提交,origin/develop
则这两个命令完全相同。origin/develop
如果我忘记更新我的本地develop
(假设这个分支最终会被推送到origin/develop
),我会倾向于使用。
回答by torek
As I wrote in my other (long) answer to your previous question Why is "rebase --onto ABC" different than "rebase ABC"?, both of these commands turn off --fork-point
mode, so—provided that both develop
and origin/develop
resolve to the same commit hash, as they do in your question premise—the two commands will do the same thing.
正如我在对您之前的问题的另一个(长篇)回答中所写的那样,为什么“rebase --onto ABC”与“rebase ABC”不同?,这两个命令的关闭--fork-point
模式,所以提供的这两个develop
和origin/develop
决心同犯散,因为他们在你的问题的前提下,这两个命令会做同样的事情做。
Omitting the <upstream>
argument turns --fork-point
on by default, and the reflog for the branch's configured upstream may have a lot of data in it. In this case, they may act quite differently. By adding an explicit --no-fork-point
, you can prevent git merge-base --fork-point
from dropping upstream-removed commits.
省略<upstream>
参数--fork-point
默认开启,分支配置的上游的 reflog 中可能有很多数据。在这种情况下,它们的行为可能完全不同。通过添加显式--no-fork-point
,您可以防止git merge-base --fork-point
删除上游删除的提交。