git branch - Git divide commits between branches -
currently have remote develop branch commits like:
c1 -> c2 -> c3 -> c4 -> c5 -> c6
(cx commit x)
i need divide these commits new branches, this:
develop branch: c1 c2 c6
newbranchtwo: c3 c5
newbranchthree: c4
(newbranchtwo , newbranchthree not need become remote)
how can achieve this?
git rebase friend.
one easy way accomplish use git branch produce 3 identical branches (develop, newbranchtwo, newbranchthree), edit down using
git rebase --interactive c1 ...replacing c1 commit's hash or other ref. in interactive mode, git first pop open text editor shows entire history, , commits wil applied in order top bottom according deletions or reorderings make in editor. remove c3 through c5 develop, , make corresponding edits other branches.
you can skip interactive mode , use git reset , git rebase --onto move c6 onto c2 , name develop, , same c3 onto upstream head , c5 onto (etc). without knowing actual hashes or parent of c1, i'll leave actual commands there git rebase documentation.
(you put git-revert in tags, if you're trying divide commits, git revert won't help: records new commits undo existing commits without erasing them. if want history does, rather c1 c2 c3 c4 c5 c6 rev-c5 rev-c4 rev-c3, you'll need rebase or otherwise edit history.)
as you're aware, time you're adjusting commits have happened, change hashes , may make difficult has branched already. haven't pushed remote develop branch yet!
Comments
Post a Comment