git pull --rebase

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5860944/
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-19 05:24:18  来源:igfitidea点击:

git pull --rebase

gitgit-rebase

提问by Mot

Start situation (no unpushed changes, >indicates the current branch):

启动情况(没有未推送的变化,>表示当前分支):

o C [> master][origin/master]
|
o B
|
o A
|
...

After a git fetchthe log structure often looks like

git fetch日志结构之后通常看起来像

o E [origin/master]
|
o C'
|
o B'
|
o D
|
| o C [>master]
| |
| o B
|/
o A
|
...

Now git rebase origin/master masteroften produces conflicts. Is git pull --rebasesmarter and just uses git resetto make masteralso point to Eif master==origin/masterinitially?

现在git rebase origin/master master经常产生冲突。是否git pull --rebase更聪明并且只是git reset用来使最初master也指向Eif master== origin/master

采纳答案by grzuy

git pull --rebaseis similar to what the following would do:

git pull --rebase类似于以下操作:

git fetch
git rebase

So in your case it will leave the repository like this:

因此,在您的情况下,它将像这样离开存储库:

o C [> master]
|
o B
|
o E [origin/master]
|
o C'
|
o B'
|
o D
|
o A
|
...

Note that the two commits you have are different from originwhere re-created on top of commit E.

请注意,您拥有的两次提交与origin在提交 E 之上重新创建的位置不同。

回答by mahalie

You can pull with rebase instead of merge - that's the way my team works and it works quite well.

您可以使用 rebase 而不是合并来拉取 - 这就是我的团队的工作方式,而且效果很好。

From "A few git tips you didn't know about":

来自“你不知道的一些 git 技巧”:

Because branch merges in git are recorded with a merge commit, they are supposed to be meaningful—for example, to indicate when a feature has been merged to a release branch. However, during a regular daily workflow where several team members sync a single branch often, the timeline gets polluted with unnecessary micro-merges on regular git pull. Rebasing ensures that the commits are always re-applied so that the history stays linear.

You can configure certain branches to always do this without the --rebase flag:

#make 'git pull' on master always use rebase
$ git config branch.master.rebase true

You can also set up a global option to set the last property for every new tracked branch:

# setup rebase for every tracking branch
$ git config --global branch.autosetuprebase always

因为 git 中的分支合并记录在合并提交中,所以它们应该是有意义的——例如,指示何时将功能合并到发布分支。然而,在几个团队成员经常同步一个分支的日常工作流程中,时间线会被定期 git pull 上不必要的微合并污染。变基确保提交总是重新应用,以便历史保持线性。

您可以将某些分支配置为始终在没有 --rebase 标志的情况下执行此操作:

#make 'git pull' on master always use rebase
$ git config branch.master.rebase true

您还可以设置一个全局选项来为每个新的跟踪分支设置最后一个属性:

# setup rebase for every tracking branch
$ git config --global branch.autosetuprebase always

回答by Adam Spiers

git pull --rebaseis NOTthe same as git fetch; git rebase. Unfortunately the git-pullman page is rather cryptic about the difference:

git pull --rebase一样的git fetch; git rebase。不幸的是,git-pull手册页对差异相当含糊:

   --rebase
       Rebase the current branch on top of the upstream branch
       after fetching. If there is a remote-tracking branch
       corresponding to the upstream branch and the upstream branch
       was rebased since last fetched, the rebase uses that
       information to avoid rebasing non-local changes.

It turns out that the difference doesn't involve git resetas the original poster guessed - in fact it involves the reflog(see hereif you haven't encountered that term before).

事实证明,差异并不git reset像原始海报所猜测的那样涉及- 实际上它涉及引用日志(如果您以前没有遇到过该术语,请参见此处)。

For the complete story around the extra magic in git pull --rebase, see this answer:

有关 中额外魔法的完整故事git pull --rebase,请参阅此答案:

https://stackoverflow.com/a/11531502/179332

https://stackoverflow.com/a/11531502/179332