问题
i have been developing committing on the master branch, and would like to move all commits beyond the "initial commit" to a separate development branch, and keep the master for release versions.
right now, my tree looks like this:
master: A - B - C - D - E - F
i would like it to look like this:
development: B - C - D - E - F
/
master: A -----------------
that way i would be able to merge a release like so:
development: B - C - D - E - F --- X
/ \
master: A ----------------------- Y
can someone suggest the best way to do this? i've seen other answers with similar but not exact cases, but i don't want to take the chance of screwing something up.
回答1:
To be simple:
(on master)
git branch development
git reset --hard A
回答2:
first create a new branch for commit F (last commit on branch master):
git checkout -b dev master # or directly using the commit hash:
git checkout -b dev SHA1_OF_F # if master is currently checked out:
git checkout -b dev
then, move back your master branch (without destroying your working tree)
git branch -f master SHA1_OF_A
checkout master again if you want to continue working on it:
git checkout master
if you don't care about your working tree (it is clean, i.e. there are no uncommitted nor unstaged changes, you can use git reset --hard
as suggested by @manojlds in his answer.
this alters (i.e. prunes) history of the master branch, so be sure you understand the consequences. if your changes have already been pushed to a public repo other users will have the development commits already contained in master
and would have to reset their branch too.
来源:https://stackoverflow.com/questions/6722539/moving-all-commits-beyond-initial-commit-off-master