git - 远程分支后面的本地分支(pull、rebase、fetch、merge)

标签 git github branch

如果我在我的分支 branch1 上工作,然后在我的团队成员也在 branch1 上工作时我推送了一些提交——当我的团队需要的时候成员 push 他的更改,他现在落后了。

他获取我最近的提交并尝试将他的更改与我的更改 merge 的最简单方法是什么?假设他在意识到此错误之前已经提交了更改。

我以为你会这样做:

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

但这似乎根本不起作用。

我相信你会做一个rebase,但我不确定这个过程;所有人都在谈论用 masterrebase——但我现在不想用 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

enter image description here

图片来源: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 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

关于git - 远程分支后面的本地分支(pull、rebase、fetch、merge),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35355879/

相关文章:

Git - 在 github 上使用端口 9418 进行远程操作

git - 拿一个当前的 Git 分支和 "reset"它的内容来掌握

git - 版本控制机器特定配置

Git存储库不克隆

windows - IntelliJ 升级到 Windows 8.1 后无法启动 Git

git - 如何增加 git reflog 输出的条目数?

github - 如何从 GitHub Web 更新 fork 的 repo?

visual-sourcesafe - 项目级别的 SourceSafe 合并

github - github上fork和branch的区别

svn - 如何使用 TortoiseSVN 和 Subversion 在新分支中提交当前更改?