如何合并位于不同本地存储库/文件夹中的两个 git 分支?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3402599/
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
How do you merge two git branches that are in different local repos/folders?
提问by Michael Waxman
I have:
我有:
folder_a/app_1.0
folder_b/app_1.1
And let's just say I'm working off of the master branch in both folders/repos.
假设我正在两个文件夹/存储库中的主分支上工作。
How can I merge the branches together?
如何将分支合并在一起?
回答by Stephen Jennings
You must pull the commits from one repository into the other, do the merge, then pull back into the first (if you want both repositories to contain all the commits).
您必须将提交从一个存储库拉入另一个存储库,进行合并,然后拉回第一个(如果您希望两个存储库都包含所有提交)。
# switch to repo A
cd folder_a
# Add repo B as a remote repository
git remote add folderb /path/to/folder_b
# Pull B's master branch into a local branch named 'b'
git pull folderb master:b
# Merge b into A's master branch
git merge b
# Switch to repo B
cd ../folder_b
# Add repo A as a remote repository
git remote add foldera /path/to/folder_a
# Pull the resulting branch into repo B's master branch
git pull foldera master:master