简体   繁体   English

Git-将基础分支与当前分支合并

[英]Git - merge base branch with current branch

Lets say I have a git branch (call it v1.1) that was created based on the branch named v1.0. 可以说我有一个基于名为v1.0的分支创建的git分支(称为v1.1)。 I make changes to files in the v1.1 branch and other engineers make changes in the v1.0 branch. 我在v1.1分支中更改了文件,其他工程师在v1.0分支中进行了更改。 I have not yet finished making my changes to my branch (v1.1) and I want to include the changes that were made in v1.0 to my v1.1 branch. 我尚未完成对分支(v1.1)的更改,我想将v1.0中所做的更改包括到v1.1分支中。 How so I do this? 我该怎么做? I can find plenty of documentation on how to merge my changes from my branch (v1.1) back into the v1.0 branch but nothing on how to refresh my a branch with updates from the base branch. 我可以找到很多有关如何将分支(v1.1)中的更改重新合并到v1.0分支中的文档,但是没有关于如何使用基础分支中的更新刷新分支的文档。

I would just switch to v1.1 : 我只是切换到v1.1

git checkout v1.1

then merge v1.0 into it: 然后将v1.0合并到其中:

git merge v1.0

a related post: https://superuser.com/questions/224085/git-merge-master-into-a-branch 相关文章: https : //superuser.com/questions/224085/git-merge-master-into-a-branch

This partly depends on what you need the branch for. 这部分取决于您需要分支的用途。 It looks like v1.1 in your case would be a branch that might be around for a while, so merging is probably fine. 在您的情况下,v1.1似乎是一个分支,可能会存在一段时间,因此合并可能很好。

But in other scenarios, such as if your branch is local only, and you are going to put it back in v1.0 when you are done with it, you might want to rebase instead. 但是在其他情况下(例如,如果您的分支仅是本地分支,并且在将其完成后将其放回v1.0中),则可能需要重新设置基准。

git checkout v1.1

then rebase 然后变基

git rebase v1.0

This will give you the changes in v1.0 without putting a merge commit into the history. 这将为您提供v1.0中的更改,而无需将合并提交放入历史记录。

Both merge and rebase will do what you are looking for, you just have to chose the right one for what you are doing. 合并和变基都可以满足您的需求,您只需要为您的工作选择正确的对象即可。

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

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