git - How to separate changes from master into another branch without overwriting history? -


recently have started implement new experimental feature project. unfortunately forgot branch before starting , pushed several commits onto shared repository server master branch. since other people may have checked commits out avoid overwriting history on server.

due changes master unstable, not good. therefore revert changes made master, create separate branch contain these changes , still able reintroduce (merge) them master once stable enough.

this answer uses command line tools , takes different approach managing branches. may less confusing using multiple resets of various flavors.

the revert command in git 1.7.2 , later can revert multiple commits in 1 command:

git revert last-stable.. 

this create revert commits each commit after last-stable to, , including, current head commit (in reverse order). if dealing many unwanted commits, may want revert them in single commit:

git revert -n last-stable.. git commit # edit message explain reverting multiple commits 

here how put other commands re-establish experimental branch on top of revert commit(s):
(assumes shared branch named master)

# make sure have latest shared master git checkout master git pull  # mark last experimental commit git branch experimental  # revert experimental commits git revert last-stable.. # optionally use -n , manually commit batched reverts  # replay experimental commits on top of reverted commits git checkout -b experimental master git cherry-pick last-stable..experimental@{1} 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -