本地分支落后于远程分支(拉取、变基、获取、合并)

3
如果我正在我的分支branch1上工作,然后当我的团队成员也在branch1上工作时,我推送了一些提交--当他想要推送他的更改时,他现在落后了。
那么他获取我最新的提交并尝试将他的更改与我的合并的最简单方法是什么?假设他在意识到这个错误之前已经提交了他的更改。
我认为你可以做以下操作: git pull origin/branch1 && git merge origin/branch1 但是这似乎根本不起作用。
我相信你需要进行一个rebase,但我不确定具体过程;所有人都在谈论如何使用master进行rebase--但此时我不想对master做任何操作。
1个回答

4

git pull origin/branch1 && git merge origin/branch1

git pull

git pull实际上是这两个命令的别名:git fetch + git merge,因此您命令的第二部分是无用的。


获取更改的方式 - 几个选项:

# Update your local repo with the latest code:
git fetch --all --prune

# Merge the changes (you already did a pull)
git merge origin branch1

或者:

# grab & merge the latest changes into your current branch 
git pull origin branch1

rebase

如果你希望你的更改在其他更改之上,则可以在拉取内容时使用--rebase标志。

# As before - update your local repo with the latest code:
git fetch --all --prune

# Merge the changes with the rebase flag
git pull --rebase origin/branch1

在此输入图片描述

图片来源:http://blogs.atlassian.com/


Stash + rebase 自动化

您可以设置以下配置:

rebase.autoStash + pull.rebase

rebase.autoStash

当设置为true时,在操作开始前自动创建一个临时存储区,并在操作结束后应用它。
这意味着您可以在脏的工作树上运行rebase

但是请谨慎使用:成功的rebase之后最终的存储区应用可能会导致非常复杂的冲突。默认值为false。

pull.rebase

当为true时,在运行"git pull"时将分支重新设置到已获取的分支的顶部,而不是合并默认远程的默认分支。

git config pull.rebase true
git config rebase.autoStash true

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接