简体   繁体   中英

Git, moving development from one branch to another

I have a Git repository containing a Java library with two branches: main and jdk8 .

The jdk8 branch is the main development branch, with all changes merged into main , whereas the main branch is modular and based on jdk11, with module-info.java files and changes in Gradle build files, different build plugins and modular versions of dependencies, where available. The source code itself is close to identical between the two branches.

What I'd like to do, is to stop developing on the jdk8 branch and start using main as the main development branch, merging changes into the jdk8 branch, from there on.

Some googling led me to these:

How to make empty merge commit (ignoring changes)?

Git - Ignore files during merge

And from that I came up with this strategy:

git checkout jdk8

git merge -s ours main

I have tested this and it looks like it works as expected, that is, allows me to start developing on main and merge the changes into the jdk8 branch, excluding any modified files that don't belong there during merge (perhaps I can use git attributes to exclude the module-info.java files automatically, for example).

On the face of it, this appears quite manageable, but since my understanding of Git is quite rudimentary, I'm wondering if this will cause some problems down the road, is there perhaps a better ("correct" even?) way of doing this?

The simplest that safest way to do this is simply to rename your branches.

Let's say that your current main will be called 'future-dev'

git checkout main
git branch -m future-dev

and now you rename the jdk8 to main

git checkout jdk8
git branch -m main

and now you can continue to work as usual on your new main (that was originally your jdk8 branch).

You can (or not, as you want and when you want) merge the other branch (the old main that is now the future-dev branch.

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