简体   繁体   English

什么时候应该使用git pull --rebase而不是git pull?

[英]When should I use git pull --rebase instead of git pull?

I have a local commit [A] and a branch which points at commit [B]. 我有一个本地提交[A]和一个指向提交[B]的分支。 I need to pull changes before pushing the commit. 我需要在提交之前先进行更改。

Scenario 1: 方案1:

Changes of commit [A] do not affect anything changed on commit [B] 提交[A]的更改不会影响提交[B]上的任何更改

git pull should be fine, pull should not overwrite anything. git pull应该没问题,pull应该不会覆盖任何东西。 Same for using git pull --rebase . 与使用git pull --rebase相同。

Scenario 2: 方案2:

Changes of commit [A] and commit [B] affect the same file 提交[A]和提交[B]的更改会影响同一文件

git pull should be fine, git should automerge everything. git pull应该没问题,git应该自动合并所有内容。 Same for using git pull --rebase . 与使用git pull --rebase相同。

Scenario 3: 方案3:

Changes (or deletions) of commit [A] and commit [B] affect the lines of code. 提交[A]和提交[B]的更改(或删除)会影响代码行。

git pull results into merge conflicts which I need to remove manually. git pull结果变成合并冲突,我需要手动删除。 Same for using git pull --rebase . 与使用git pull --rebase相同。

Am I wrong? 我错了吗? In which cases I need to use git pull --rebase ? 在哪种情况下,我需要使用git pull --rebase If you pull changes you need to rebase the commit anyway, either by auto merge , no merge or solving merge conflicts . 如果您进行更改,则无论如何都需要通过auto mergeno merge或解决merge conflicts来使提交的基准变大。

You can use git pull --rebase in all three cases. 在这三种情况下都可以使用git pull --rebase However, in the scenarios 2 and 3, you will have a new merge commit. 但是,在方案2和3中,您将有一个新的合并提交。 The message will say that you are merging Branch 'foo' into branch 'foo' and with branches that have a lot of changes can make the history really confusing. 该消息将表明您将Branch 'foo' into branch 'foo'合并Branch 'foo' into branch 'foo' ,并且分支进行了很多更改,这会使历史确实令人困惑。 Using git pull --rebase will not have these merge commits and will show a fairly straight forward history in the git log. 使用git pull --rebase将没有这些合并提交,并且将在git日志中显示相当简单的历史记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM