远程分支后面的本地分支(拉取,重定位,取数,合并) [英] Local branch behind remote branch (pull, rebase, fetch, merge)

查看:217
本文介绍了远程分支后面的本地分支(拉取,重定位,取数,合并)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在我的分支上工作, branch1 ,然后我推送一些提交,而我的团队成员也在处理 branch1 - 当我的团队成员推出他的更改时,他现在已经落后了。



最简单的方法是让他获得我最近的提交,并试图将他的变化与我的合并?假设他已经在发现这个错误之前进行了修改。



我以为你会这样做:

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



但这似乎不起作用。



我相信你会做一个 rebase ,但我不确定这个过程;所有讨论的人都在使用 master 完成 rebase - 但我不想用<$ c $ b $ master $ <$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ c> git pull origin / branch1&& git merge origin / branch1




git pull



git pull 实际上是这两个命令的别名: git fetch + git merge 所以你的命令的第二部分是无用的。






- 几个选项:

 #使用最新的代码更新您的本地回购:
git fetch --all --prune

#合并更改(您已经做了一次拉)
git合并原始分支1

OR:

 #grab&将最新的变化合并到您当前的分支中
git pull origin branch1






rebase



如果您希望将更改置于其他更改之上,那么您可以在拉动内容时使用 - rebase 标志。

 #与以前一样 - 使用最新代码更新本地回购:
git fetch --all --prune

#将更改与rebase标志合并
git pull --rebase origin / branch1



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




自动存入+重新绑定



您可以使用这些配置设置:



rebase.autoStash + pull.rebase


rebase。 autoStash



设置为true时,会在操作开始前自动创建临时存储,并将其应用于操作结束。

这意味着您可以在脏 worktree 上运行 rebase 。然而,谨慎使用:成功 rebase 后的最终隐藏应用程序可能会导致非平凡的冲突。默认为false。



pull.rebase



如果为true,则rebase分支位于提取分支的顶部,而不是在运行git pull时合并默认分支和默认分支。



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


If I am working on my branch, branch1 and then I push some commits while my team member was also working on branch1--when it comes time for my team member to push his changes, he's now behind.

What is the easiest way for him to get my most recent commits, and attempt to merge his changes with mine? Let's assume he has already committed his changes before realizing this error.

I thought you'd do:

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

but that doesn't seem to work at all.

I believe you'd do a rebase, but I'm unsure of the process; all anyone talks about is doing rebase with master--but I don't want to do anything with master at this point.

解决方案

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

git pull

git pull is actually an alias to those 2 commands: git fetch + git merge so your second part of the command is useless.


The way to grab changes is this - Several option:

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

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

OR:

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


rebase

If you want your changes to be on top of the other changes then you can use the --rebase flag when pulling the content.

# 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

Image src: http://blogs.atlassian.com/


Stash + rebase automatically

You have those config which you can set:

rebase.autoStash + pull.rebase

rebase.autoStash

When set to true, automatically create a temporary stash before the operation begins, and apply it after the operation ends.
This means that you can run rebase on a dirty worktree.

However, use with care: the final stash application after a successful rebase might result in non-trivial conflicts. Defaults to false.

pull.rebase

When true, rebase branches on top of the fetched branch, instead of merging the default branch from the default remote when "git pull" is run.

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

这篇关于远程分支后面的本地分支(拉取,重定位,取数,合并)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆