简体   繁体   English

从主分支更新开发分支,而不会丢失开发中的任何更改

[英]Update develop branch from the master branch without losing any changes in develop

hi I have a develop branch based on master branch. 嗨我有一个基于master分支的开发分支。 I make changes in the develop branch. 我在开发分支中进行了更改。 Now, my question is if the master branch is to be updated, how can I upgrade the develop branch based on the master branch Without losing my changes in develop branch? 现在,我的问题是如果要更新主分支,我如何基于主分支升级开发分支而不会丢失我在开发分支中的更改?

Depends on what you mean "upgrade", but I would assume you want your develop branch to have the commits master has. 取决于你的意思是“升级”,但我认为你希望你的开发分支拥有提交大师。

So you need a git merge or a git rebase . 所以你需要一个git mergegit rebase

# merge master into develop
git checkout develop
git merge master

or 要么

# rebase develop on top of master
git checkout develop
git rebase master

Or if your master is on a server and you want to get the changes from your origin, you can have to do the same things, but with the pull command. 或者,如果您的主服务器位于服务器上并且您希望从原始服务器获取更改,则可以使用pull命令执行相同的操作。

git checkout develop
git pull #or git pull --rebase

Note that your current working directory must be clean. 请注意 ,您当前的工作目录必须是干净的。 Otherwise you must commit (or stash) your changes, in order to get things from master. 否则,您必须提交(或存储)您的更改,以便从master获取内容。

I would advise you to use the rebase solution (see mereg vs rebase ). 我建议你使用rebase解决方案(参见mereg vs rebase )。 Assuming you are in your personal development branch (no one else uses this branch) 假设您在您的个人开发分支中(没有其他人使用此分支)

1st save your current dev (in ) : 1保存当前dev(in):

git add <all files you created> 
# -am is ; a: all added an modified    m: message follows
git commit -am "<comment your commit>"    
git push origin <my-dev-branch>

From this point you cannot loose anything as there is a copy on the remote 从这一点开始, 你不能放松任何东西,因为遥控器上有副本

Then update local with remote info 然后使用远程信息更新本地

git fetch --all
git rebase master

at this point you might have to deal with a few merge conflict 此时你可能不得不处理一些合并冲突

git mergetool

check this for setting a good merge tool 选中此项以设置好的合并工具

Once you have solved all merge conflict, and re-tested your code you will push again to server forcing (-f) the branch update 一旦解决了所有合并冲突,并重新测试了代码,您将再次推送到服务器强制 (-f)分支更新

git push -f origin <my-dev-branch>

Go to develop and pull using rebase. 去开发和使用rebase。

git checkout develop
git pull --rebase origin master

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

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