Reputation: 1717
Let say I have following git
structure
1--2--3--4--5--6--7--8 (master-branch)
\
9--10--11--12(custom-branch)
How can I get into the following git
structure?
1--2--3--4 (master-branch)
\
5--6--7--8--9--10--11--12 (custom-branch)
Upvotes: 2
Views: 438
Reputation: 11
I have an alternative which I feel it is safer:
git checkout "HEAD~4"
git branch -f master
So first you put your HEAD where you want your master branch tip (commit 4) And then you create there a branch called master (you have to force it, -f because the name already existed).
Or, if HEAD is already in master, then only:
git branch -f master HEAD~4
Upvotes: 0
Reputation: 1903
I believe you would just checkout master
and rewind it a few commits. custom-branch
won't be changed.
git checkout master
git reset --hard "HEAD~4"
Warning: Using --hard
gets rid of any local changes. However, without it, the changes in all the commits you rewound will end up as local changes.
Upvotes: 4