简体   繁体   English

Git合并分支,掌握发展

[英]Git merge branches, master into develop

I have a develop branch and a master branch in Git for the same project. 我在同一项目的Git中有一个开发分支和一个主分支。

The develop branch has different deployment code to master. 开发分支需要掌握不同的部署代码。

I had a set of changes to make for a client so made them to master as they wanted it live quickly. 我为客户进行了一系列更改,因此使他们掌握了他们想要的快速生存的方式。

Now the master branch does not contain these changes. 现在,master分支不包含这些更改。

I am wanting to know if i have to make these changes back to the develop branch manually or if there is a way (or safe) to merge master back into develop branch so both are up to date with the latest changes? 我想知道是否必须手动将这些更改返回到developer分支,或者是否有一种方法(或安全的方法)将master合并回developer分支,以便两者都与最新更改保持最新?

Thanks 谢谢

The safest way would probably be to cherry pick the commits with these changes off the one branch onto the other. 最安全的方法可能是将这些更改从一个分支转移到另一个分支。 This would ensure that only the changes you intend get on to the branch. 这样可以确保只有您打算进行的更改才能进入分支。

You can rebase your develop branch onto master branch, in case you have any merge conflicts (if you have changed the same lines of codes differently in both the branches), you should solve the conflicts and then just git add the changes and continue the rebase. 您可以将自己的develop分支重新设置为master分支,以防万一发生任何合并冲突(如果您在两个分支中更改了相同的代码行),则应解决冲突,然后通过git添加更改并继续进行重新构建。

 git checkout develop
 git rebase master

--- solve the conflicts if there are any, after solving it, ---

git add .
git rebase --continue (until the conflicts are solved)

Another way is to use git cherry-pick the commits from master branch to develop branch. 另一种方法是使用git cherry-pick从master分支提交到开发分支。 You might need to solve merge conflicts in this method as well. 您可能还需要使用此方法解决合并冲突。

You could do the following [IF develop is the branch which is messed up and has to be made same as master ], 您可以执行以下[如果develop是混乱的分支,并且必须与master相同],

git checkout develop
git reset --hard origin master  # DISCLAIMER: This will remove all your changes in develop
git fetch origin master

Now your develop is exactly like master . 现在您的develop完全像master一样。

However, if you still want to keep the changes in develop but want the things that are there in the master too, do the following, 但是,如果您仍想保留的变化develop ,但希望是存在的东西master得,做到以下几点,

git checkout develop
git rebase master  # Might have to fix some conflicts here

and you're done. 到此为止。

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

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