GIT:如何将一个分支的内容复制到另一个分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35174544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
GIT: How to copy contents of one branch to other branch?
提问by Balasekhar Nelli
I have 'develop' and 'InitialPomChanges' branches. I want to copy all the contents of develop branch to InitialPomChanges branch.
我有 'develop' 和 'InitialPomChanges' 分支。我想将 develop 分支的所有内容复制到 InitialPomChanges 分支。
回答by David Deutsch
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:
假设您想用开发中的内容覆盖 InitialPomChanges 的所有内容(即您希望 InitialPomChanges 的内容与开发完全匹配),请执行以下操作:
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
.
这将使 InitialPomChanges 中的最后一次提交与开发中的最后一次提交匹配。为了使两个分支之间的未来合并更容易,现在做一个git merge develop
.
Alternatively, if you want to change the contents of InitialPomChanges and do the merge in one single commit, you can do:
或者,如果您想更改 InitialPomChanges 的内容并在一次提交中进行合并,您可以执行以下操作:
git checkout InitialPomChanges
git merge -s theirs develop
回答by TheGeorgeous
You can use git merge
or git rebase
您可以使用git merge
或git rebase
If you are on the InitialPomBranch, you can simply run
如果你在 InitialPomBranch 上,你可以简单地运行
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
第一个会将开发分支的所有提交合并到 InitialPomBranch。第二个将把 develop 分支的所有提交放在 InitialPomBranch 的第一个提交之下
Edit: Rebase will change the SHA hashes of all the commits of the InitialPomBranch. So you will have to run
编辑:Rebase 将更改 InitialPomBranch 的所有提交的 SHA 哈希值。所以你必须跑
git push -f origin InitialPomBranches
to push all the changes
推动所有变化
回答by Mathi Maheswaran
$ git merge develop
Make sure that your current branch is InitialPomChanges
确保您当前的分支是InitialPomChanges