Reputation: 364
I have a commit which contains multiple (unwanted)branches, by git log --graph i got this:
commit 417bb7dfd7d7230fd1c859414d2aa231e72e24e6 (HEAD -> Feature1, master, Feature2)
How can i move Feature1,Feature2 branches from commit 417bb7dfd7d7230fd1c859414d2aa231e72e24e6 to different commits?
thank you for your help.
Upvotes: 1
Views: 1555
Reputation: 21938
This seems to be predicated on a misunderstanding.
These branches are not in the commit.
In git, branches are labels pointing to commits. A commit can have any number (zero, four, a thousand, whatever) of branches pointing at it.
A---B---C---D
\ \ \
\ \ master
\ \
\ branch-abc
\
branch-xyz
Here above, master
, branch-abc
and branch-xyz
happen to point at different commits, but if you did
git checkout branch-abc
git merge master
You would then get
A---B---C---D
\ \
\ master, branch-abc
\
branch-xyz
...where, yes, master
and branch-abc
do point to the same commit.
If, for any reason, you do need to move or delete a branch, this is easy (but then again, I have to stress the important part, being to understand what branches are for)
# move a branch to commit abc123 (when the branch is NOT checked out)
git branch -f my_branch abc123
# or if the branch IS checked out
git reset --hard abc123
# delete a branch
git branch -d my_branch
# ...which will complain in case the branch isn't fully merged yet
# in which case you can then force it
git branch -D my_branch
Upvotes: 5