远程分支后面的本地分支(pull,rebase,fetch,merge)

时间:2016-02-12 06:03:57

标签: git github branch

如果我正在我的分支机构branch1上工作,那么当我的团队成员也在branch1工作时,我会推送一些提交 - 当我的团队成员推动他的更改时,他现在落后了。

最简单的方法是让他获得我最近的提交,并尝试将他的更改与我的合并?让我们假设他在实现此错误之前已经提交了更改。

我以为你做了:

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

但这似乎根本不起作用。

我相信你做rebase,但我不确定这个过程;所有人都在跟rebase进行master的讨论 - 但我现在不想对master做任何事情。

1 个答案:

答案 0 :(得分:3)

  

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

enter image description here

图片src:http://blogs.atlassian.com/

Stash + rebase自动

您可以设置以下配置:

rebase.autoStash + pull.rebase

  

rebase.autoStash

     

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

     

但是,谨慎使用:成功rebase后的最终存储应用程序可能会导致非平凡的冲突。默认为false。

     

pull.rebase

     

如果为true,则rebase会在获取的分支上分支,而不是在" git pull"时将默认分支与默认分支合并。运行。

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