繁体   English   中英

如何将远程分支合并到本地分支?

[英]How can I merge remote branch to local branch?

我们的项目有一个开发分支。 我基于develop分支创建了一个bug-fix分支,并更改了一个文件a.java。 我知道另一个人改变了a.java并在我修复bug时合并开发分支。

现在我已经修复了这个bug,我想合并我的代码来开发分支,但在我这样做之前,我想把更改(因为其他人也改变了a.java)到我的本地分支来测试它是否有效, 我对吗? 我该怎么做?

首先,我通过' git pull ' 删除了所有代码,我在我的bug修复分支中。 然后运行' git merge develop ',它输出空。 然后我' git merge origin / develop '。输出低于错误。

Updating 46f689b..3011608
error: Your local changes to the following files would be overwritten by merge:
        projectA/a.java
Please commit your changes or stash them before you merge.
Aborting

如何将开发分支合并到我的工作目录?谢谢。

通常情况下,这是我喜欢做的事情,

git stash # Stash your local changes
git pull  # Update code
git stash apply # Merge your local changes

现在,为了澄清,如果你需要同步另一个分支,你可以在你的git pull之前切换分支。 从那里你可以回到你的bug修复分支并运行git stash apply然后与你的develop分支合并。

因为您对该文件进行了一些更改

Please commit your changes or stash them before you merge.

请按照:

# save current work state
git stash
# merge from develop
git merge origin/develop
# recover current work state (get the last item of stash)
git stash pop

由于您没有在bug分支上推送本地提交,因此您需要在更新(由其他开发人员) origin/bug分支之上对它们进行重新绑定

为此,请确保首先设置配置

git --global config pull.rebase true
git --global config rebase.autoStash true

(从任何文件夹只进行一次)

然后,当您在当前分支中时,您可以通过简单包含其他贡献:

git pull.

现在,确保所有内容都已提交,并且:

git checkout develop
git pull

最后,合并开发

git checkout bug
git merge develop

在合并其他更改之前,您需要将更改提交或存储到projectA / a.java。

提交示例:

$ git add projectA/a.java
$ git commit -m "my change message"
$ git pull origin/develop

藏匿示例:

$ git stash
$ git pull origin/develop
$ git stash apply

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM