git 如何从另一个分支获取更改

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37709298/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:15:15  来源:igfitidea点击:

How to get changes from another branch

git

提问by Anthony

I am currently working on featurexbranch. Our master branch is named branch our-team. Since I started working on featurex, more changes have been made to branch our-team. Before I push featurexfor merging, I would locally like to get all changes from our-teambranch into featurexso that I can ensure everything works as expected.

我目前在featurex分支上工作。我们的主分支名为 branch our-team。自从我开始工作以来featurex,对 branch 进行了更多的更改our-team。在我推动featurex合并之前,我希望在本地将所有更改从our-team分支导入,featurex以便我可以确保一切按预期工作。

I have done this locally to get all the latest changes from our-team.

我已在本地完成此操作以从our-team.

git checkout our-team
git pull

How can I do that?

我怎样才能做到这一点?

采纳答案by JulCh

You can use rebase, for instance, git rebase our-teamwhen you are on your branch featurex

例如,当你在你的分支上时,你可以使用rebasegit rebase our-teamfeaturex

It will move the start point of the branch at the end of your our-teambranch, merging all changes in your featurexbranch.

它将在分支的末尾移动分支的起点our-team,合并分支中的所有更改featurex

回答by Jad Chahine

  1. go to the master branch our-team

    • git checkout our-team
  2. pull all the new changes from our-teambranch

    • git pull
  3. go to your branch featurex

    • git checkout featurex
  4. merge the changes of our-teambranch into featurexbranch

    • git merge our-team
    • or git cherry-pick {commit-hash}if you want to merge specific commits
  5. push your changes with the changes of our-teambranch

    • git push
  1. 转到主分支 our-team

    • git checkout 我们的团队
  2. our-team分支中提取所有新更改

  3. 去你的分行 featurex

    • 结帐 featurex
  4. our-team分支的更改合并到featurex分支中

    • 合并 our-team
    • 或者git cherry-pick{commit-hash}如果你想合并特定的提交
  5. 使用our-team分支的更改推送您的更改

Note: probably you will have to fix conflicts after merging our-teambranch into featurexbranch before pushing

注意:在将our-team分支合并到featurex分支之后,您可能必须在推送之前修复冲突

回答by heisenberg

git fetch origin our-team

or

或者

git pull origin our-team

but first you should make sure that you already on the branch you want to update to (featurex).

但首先你应该确保你已经在你想要更新的分支上(featurex)。

回答by Pierre Fouilloux

You are almost there :)

你快到了:)

All that is left is to

剩下的就是

git checkout featurex
git merge our-team

This will merge our-team into featurex.

这会将我们的团队合并到 featurex 中。

The above assumes you have already committed/stashed your changes in featurex, if that is not the case you will need to do this first.

以上假设您已经在 featurex 中提交/隐藏了您的更改,如果不是这种情况,您需要先执行此操作。