简体   繁体   English

如何将另一个分支的值拉到我的本地分支?

[英]How do I pull values from another branch onto my local branch?

I am new to git and I am running into the following issue- I created a branch 'Test' from develop.我是 git 的新手,我遇到了以下问题——我从开发中创建了一个分支“测试”。 I am trying to pull changes from branch 'Working' (which is also based on develop) onto my local branch.我正在尝试将更改从分支“工作”(也基于开发)拉到我的本地分支。 I don't want any of my changes to affect develop or 'Working'.我不希望我的任何更改影响开发或“工作”。 How would I do this?我该怎么做?

I am not sure whether this is a merge or a rebase.我不确定这是合并还是变基。

Either will work, but the result is different.两者都可以,但结果不同。

  • git merge working will create a single, new merge commit which combines the history of both branches. git merge working将创建一个新的合并提交,它结合了两个分支的历史记录。 The commits are shared by both branches.提交由两个分支共享。
  • git rebase test working^{commit} && git push. HEAD:test && git checkout test git rebase test working^{commit} && git push. HEAD:test && git checkout test will rebase, ie copy , the commits on working to test . git rebase test working^{commit} && git push. HEAD:test && git checkout test将变基,即复制,提交workingtest The commits are now duplicated and separate versions of the commits exist in both branches.提交现在是重复的,并且两个分支中都存在提交的单独版本。

The third option is to cherry-pick, which is similar to rebase, but switches source and destination.第三个选项是 cherry-pick,它类似于 rebase,但会切换源和目标。

  • git cherry-pick test..working will cherry-pick, ie copy , the commits on working and apply them to your test branch. git cherry-pick test..working将 cherry-pick,即复制,提交working并将它们应用到您的测试分支。 The commits are duplicated and separate in both branches.提交在两个分支中都是重复和分开的。

History after merge:合并后的历史:

      D-E         -- working
     /   \
A-B-C     \       -- development
   \       \
    F-G-----M     -- test (M = merge commit)

History after rebase or cherry-pick: rebase 或 cherry-pick 后的历史:

      D-E         -- working
     /
A-B-C             -- development
   \    
    F-G-C'-D'-E'  -- test (C', D', E' = copied commits)

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

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