GIT: How to copy contents of one branch to other branch?

若如初见. 提交于 2019-12-03 09:06:35

问题


I have 'develop' and 'InitialPomChanges' branches. I want to copy all the contents of develop branch to InitialPomChanges branch.


回答1:


Assuming you want to overwrite all the contents of InitialPomChanges with what is in develop (i.e. you want the contents of InitialPomChanges to exactly match develop), do the following:

git checkout InitialPomChanges
git checkout develop .  #copies the contents of develop into the working directory
git commit -am "Making InitialPomChanges match develop"

This will make the last commit in InitialPomChanges match the last commit in develop. To make future merges between the two branches easier, it would be a good idea to now do a git merge develop.

Alternatively, if you want to change the contents of InitialPomChanges and do the merge in one single commit, you can do:

git checkout InitialPomChanges
git merge -s theirs develop



回答2:


You can use git merge or git rebase

If you are on the InitialPomBranch, you can simply run

git merge develop

or

git rebase develop

The first one will merge all the commits of the develop branch on to InitialPomBranch. The second one will put all the commits of the develop branch below the first commit of the InitialPomBranch

Edit: Rebase will change the SHA hashes of all the commits of the InitialPomBranch. So you will have to run

git push -f origin InitialPomBranches 

to push all the changes




回答3:


$ git merge develop 

Make sure that your current branch is InitialPomChanges



来源:https://stackoverflow.com/questions/35174544/git-how-to-copy-contents-of-one-branch-to-other-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!