简体   繁体   中英

How to make orphan branch as master?

Initially, I had two branches.

-->A-->B-->C [master]<-Head
             [v1]

So here master and v1 are at the same place and master is head .

Now, I created an orphan branch v2 . It has completely different codebase, the same application on new stack say older one on react and later one on vue.

-->A-->B-->C [master]<-Head
             [v1]

-->X-->Y-->Z[v2]

Now I want to make v2 as the master branch, as I consider production always must be master, so what I want in the end is.

-->A-->B-->C [v1]<-Head

-->X-->Y-->Z [master]<-Head 
             [v2]

Warning: This will delete anything on master that hasn't been committed to v1 yet. You may want to commit or back up some files first.

git checkout master
git reset --hard v2

Also you don't really need duplicate branches, and tags work fine for versions, so I'd recommend cleaning up your branches first:

git checkout v1
git tag v1
git checkout master
git branch -d v1
git branch -d v2

Warning: git reset --hard... will discard any uncommitted changes (staged or unstaged alike).

Warning 2: Although you just move a branch and don't modify any commits, this amounts to rewriting the history of master (actually, completely replacing the history of master with a different one). If you'll force-push the result to a shared or public repo that already had the history of the previous master branch, the usual caveats about history rewriting apply. See also What are the practical consequences of rewriting Git history?

git checkout master
git reset --hard v2

or

git checkout master
git reset --hard Z

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