git 将一个本地分支合并到另一个本地分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38206196/
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
merge one local branch into another local branch
提问by Nemelis
I have multiple branches which are branched off the master (each in a separate subdirectory).
我有多个分支从 master 分支出来(每个分支在一个单独的子目录中)。
- Branch1: new development, not yet completely finished
- Branch2: hotfix for a problem, but still under test
- Branch3: mess around branch, which I will not restore
- Branch1:新开发,尚未完全完成
- Branch2:修复了一个问题,但仍在测试中
- Branch3:乱七八糟的分支,我不会恢复
Before testing of the hotfix is finished I would like to have the code already available in Branch1, so I can continue developing with the fix in place.
(But since my experience with git is not that much I first started to play around with merge in a 3rd branch, especially created to mess around in, before I mess up either Branch1 or Branch2)
在修补程序的测试完成之前,我希望代码已经在 Branch1 中可用,以便我可以继续开发修补程序。
(但由于我对 git 的经验并不多,所以我首先开始在第三个分支中使用合并,特别是在我搞砸 Branch1 或 Branch2 之前创建的)
In my 3rd branch I first tried the following:
在我的第三个分支中,我首先尝试了以下操作:
git merge feature/Branch1
but this gave the following error:
但这给出了以下错误:
fatal: 'feature/Branch1' does not point to a commit
I next did a commit -a in my Branch1 and tried again, but it keeps giving the same error.
我接下来在我的 Branch1 中做了一个 commit -a 并再次尝试,但它一直给出同样的错误。
What am I doing wrong? What should I do to merge the code from - in this case - Branch1 with Branch3?
我究竟做错了什么?我应该怎么做才能合并来自 - 在这种情况下 - Branch1 和 Branch3 的代码?
回答by gabra
First, checkout to your Branch3:
首先,结帐到您的 Branch3:
git checkout Branch3
Then merge the Branch1:
然后合并 Branch1:
git merge Branch1
And if you want the updated commits of Branch1 on Branch2, you are probaly looking for git rebase
如果你想在 Branch2 上更新 Branch1 的提交,你可能正在寻找 git rebase
git checkout Branch2
git rebase Branch1
This will update your Branch2 with the latest updates of Branch1.
这将使用 Branch1 的最新更新更新您的 Branch2。