简体   繁体   中英

How do I apply git changes from master to different branch?

I have 3 branches:

  • master
  • test1
  • test2

Now I did add some changes to master.

Task is: apply these changes to test1 and test2, but save these branches separated from master.

It looks simple, but I can't manage with that.

Now, I'm trying merge test1 with master:

git checkout test1
git merge master # already up-to-date
git pull origin master # up-to-date
git push origin test1 # Everything up-to-date

No changes from master in result.

Trying rebase:

git checkout test1
git rebase master
git status

On branch test1
Your branch and 'origin/test1' have diverged,
and have 1 and 7 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)

git pull

Merge made by the 'recursive' strategy. Your branch is ahead of 'origin/test1' by 2 commits.

What is these 2 commits? I have a lot of commits in master.

Also there is still no changes from master in current branch.

So I can only revert these with

So, how can I apply latest commits from master properly?

git reset --hard origin/test1

In order to bring changes from other branches keeping them "separate" (as if they had been developed independently on separate branches) I think you should try git cherry-pick . https://git-scm.com/docs/git-cherry-pick

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