[英]How can I pull all remote changes with rebase instead of merge?
I can pull changes using git pull
, but it merges my local commits. 我可以使用
git pull
来提取更改,但它会合并我的本地提交。 Is there a git rebase
equivalent with which I can pull in remote changes? 是否有一个
git rebase
等价物,我可以用它进行远程更改?
Yes you can git pull --rebase
. 是的,你可以
git pull --rebase
。
You can also set that to be the default pull behaviour when you track a branch with git config branch.autosetuprebase always
. 当您使用
git config branch.autosetuprebase always
跟踪分支时,您也可以将其设置为默认的拉动行为。 Replace "always" with "remote" or "local" if you want to do it to those specific types of branches that you're tracking. 如果要对正在跟踪的特定类型的分支执行此操作,请将“always”替换为“remote”或“local”。
Now all you have to do is git pull
. 现在你所要做的就是
git pull
。
If for some reason you want to do a merge, you can do git pull --no-rebase
. 如果由于某种原因你想要合并,你可以做
git pull --no-rebase
。
Hope this helps. 希望这可以帮助。
UPDATE: see comments below for how to do this on existing branches. 更新:请参阅下面的评论,了解如何在现有分支机构上执行此操作。
Instead of autosetuprebase
, you can use the pull.rebase
config option to change the behavior for every git pull
(instead of only newly-created branches): 取而代之的
autosetuprebase
,您可以使用pull.rebase
配置选项来改变行为, 每 git pull
(而不是仅向新创建的分支):
[pull]
rebase = true
The difference is this will apply to non-tracking branches and any branches you had set up before enabling autosetuprebase
. 不同之处在于,这将适用于非跟踪分支机构以及您在启用
autosetuprebase
之前设置的任何分支机构。 So if you really want pull --rebase
to always be the default, pull.rebase
is the way to go! 因此,如果您真的希望
pull --rebase
始终是默认值, pull.rebase
就是您的最佳选择!
I usually use a fetch/rebase combination so my current (local) work stays at the top: 我通常使用fetch / rebase组合,所以当前(本地)工作保持在顶部:
git fetch
git rebase origin/develop
To change default behavior from merge
to rebase
In git >= 1.7.9: 要将默认行为从
merge
更改为rebase
在git> = 1.7.9中:
git config --global pull.rebase true
remove global if you want to apply for current repo only 如果您只想申请当前回购,请删除全局
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.