0

Imagine the following:

  • A bunch of related commits are done on a 'development' branch
  • These commits should have actually been done to a 'feature_x' branch
  • The 'feature_x' branch should be merged into the 'development' branch

Graphed example:

Current situation:

development (HEAD) A--B--C--D--E

Desired situation:

development         A--B
                        \
feature_x                C--D--E 

How do I create this feature branch, group these previous commits into the branch, and make the 'development' branch look like no individual commits have been done to it?

Aron Rotteveel
  • 81,193
  • 17
  • 104
  • 128
  • I don't really understand your scenario. Could you maybe illustrate with some simple `a -- b -- c` type commit "graphs"? – Mat Oct 13 '11 at 11:57
  • possible duplicate of [git: how to move some commits to new branch](http://stackoverflow.com/questions/3168370/git-how-to-move-some-commits-to-new-branch) – CharlesB Oct 13 '11 at 12:38
  • also possible duplicate of [How to move the current working branch to master branch in git](http://stackoverflow.com/q/3168370/11343) – CharlesB Oct 13 '11 at 12:40
  • Remember, branches are just pointers to commits. If you're not actually changing the history (you're not - those graphs are the same), all you're doing is moving those pointers around, which can generally be done just with `git branch`. – Cascabel Oct 13 '11 at 12:43

2 Answers2

3

You don't really need much to to that:

git checkout devel
git checkout -b feature_x
# now devel and feature_x refer to commit E
git branch -f devel <hash of commit B>
# now you're still on feature_x, but devel is at commit B
Mat
  • 202,337
  • 40
  • 393
  • 406
0
A--B--C--D--E(dev branch)
\
 \
   F--G(feature branch)

I assume you want to become like this

A--(dev branch)
\
 \
   F--G--B--C--D--E(feature branch)

You can use git rebase to do this

on the HEAD of dev branch create a temp branch for rebasing purpose

git branch temp
git rebase feature_branch

move your devbranch to commit A

git checkout dev_branch
git reset --hard <shasum of A>

move your feature branch to commit E and delete temp branch

git checkout feature_branch
git reset --hard <shasum of E>
git branch -D temp
TheOneTeam
  • 25,806
  • 45
  • 116
  • 158