简体   繁体   English

当我应该/不应该使用git pull --rebase

[英]When i should/shouldn't use git pull --rebase

Already checked those questions: 已经检查过这些问题:

When should I use git pull --rebase? 我什么时候应该使用git pull --rebase?

Git commits are duplicated in the same branch after doing a rebase 执行rebase后,Git提交在同一分支中重复

When will `git pull --rebase` get me in to trouble? 什么时候`git pull --rebase`让我陷入困境?

but what i don't understand is that some people say that you should always git pull --rebase and also others went to setting it as a default option when pulling and others said it's creating a problem. 但我不明白的是,有些人说你应该总是git pull --rebase而其他人则在拉动时将其设置为默认选项,而其他人则认为这会产生问题。

I'm facing the duplicate commits issue in git log and i guess it's because of --rebasing in the wrong time where we should only pull , I know that the difference between git pull and git pull --rebase is that git pull is trying to merge both local and remote while git pull --rebase replicate the commits. 我现在面临的重复在git的日志提交的问题,我想这是因为--rebasing在错误的时间,我们应该只pull ,我知道的区别git pullgit pull --rebase是混帐拉试图合并本地和远程,而git pull --rebase复制提交。

Scenarios: 场景:

  1. when i start my work and before doing anything new i need to pull other developers changes, should i use git pull --rebase or only git pull ? 当我开始我的工作和做任何新的事情之前,我需要拉动其他开发人员的变化,我应该使用git pull --rebase还是只有git pull and why? 为什么?
  2. when i work and commit and decide to push but then git asks me to pull first should i use git pull --rebase or git pull ? 当我工作和承诺并决定推,但然后git要求我先拉我应该使用git pull --rebase or git pull and why? 为什么?
  3. when I work and commit, work and commit (loop) and then in the middle of my work i need someone's else changes before i continue my task should i git pull or git pull --rebase ? 当我工作和提交,工作和提交(循环),然后在我的工作中我需要别人的其他更改,然后我继续我的任务应该我git pullgit pull --rebase and why ? 为什么?

Thanks 谢谢

git pull does two things - a git fetch followed by git merge . git pull做了两件事 - git fetch后跟git merge If you use git pull --rebase , it instead does git fetch followed by git rebase . 如果你使用git pull --rebase ,它会改为git fetch然后是git rebase To answer your specific questions: 回答您的具体问题:

  1. If you haven't committed any changes locally, it doesn't matter. 如果您尚未在本地提交任何更改,则无关紧要。 The result will be the same. 结果将是相同的。 The implicit git merge will be a fast-forward. 隐式git merge将是一个快进。

  2. Normally in this case you'd want to rebase; 通常在这种情况下你想要改变; you'd prefer your changes to be linear history on top of what's going on with the remote. 您希望您的更改是基于遥控器正在进行的线性历史记录。

  3. Normally you'd rebase here too. 通常你也会在这里改变。 Again, you want your local work to be added on top of the remote's history, not adding merge commits to it. 同样,您希望在远程历史记录之上添加本地工作,而不是向其添加合并提交。

All of this mess can be avoided by just not working on the remote tracking branch . 只需不在远程跟踪分支上工作就可以避免所有这些混乱。

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

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