如果我在我的分支 branch1
上工作,然后在我的团队成员也在 branch1
上工作时我推送了一些提交——当我的团队需要的时候成员 push 他的更改,他现在落后了。
他获取我最近的提交并尝试将他的更改与我的更改 merge 的最简单方法是什么?假设他在意识到此错误之前已经提交了更改。
我以为你会这样做:
git pull origin/branch1 && git merge origin/branch1
但这似乎根本不起作用。
我相信你会做一个rebase
,但我不确定这个过程;所有人都在谈论用 master
做 rebase
——但我现在不想用 master
做任何事情。
最佳答案
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/
自动存储 + rebase
你有那些你可以设置的配置:
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 runrebase
on a dirtyworktree
.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
关于git - 远程分支后面的本地分支(pull、rebase、fetch、merge),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35355879/