简体   繁体   中英

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. 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. 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 . 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.

  • git cherry-pick test..working will cherry-pick, ie copy , the commits on working and apply them to your test branch. 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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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