简体   繁体   中英

Git: Bettter way than cherry-pick to merge two branches?

Newbie on git, i have two branches in my git project, master and feature , both branches share 80% of the same code, while the other 20% are different, Now i'm working on master, i make a commit on master, and this commit also should be applied to feature branch, if i use merge, there will be conflict as the other 20% code are different, i have to use cherry-pick, and the commit history of the two branches are parallel. This is annoying as i have to cherry-pick every commit from master to feature branch.

Is there one better way to achieve this?

You have a massive problem here, because your branches already differ way too much.

To prevent this, you need to keep them in sync as much as possible.

For future scenarios like this, there are two possible approaches, both of which need to be applied from the beginning:

  1. Merge frequently from master to feature
  2. Frequently rebase feature onto master

I'm pretty sure you can check out specific files with:

git checkout <branch> <commit-ref> <filepath>

If the updates you want to push between branches are contained to specific files then that should let you sync up manually at least.

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