I'm an hg girl living in a git world. I have a common workflow that happens all the time that i cant seem to understand how it should be done in git. So let me describe how I manage with mercurial.
So I pull from my origin and I have these 4 commits
o 3:1f6b4172c41e
|
o 2:639ba9dc8afc
|
o 1:5bfb5ae3faf5
|
o 0:e0890b04d1d3
I start hacking away and make 3 more commits, but I don't push them
o 6:e48cc97b3508
|
o 5:9a4c73cfb4f9
|
o 4:e32af117ea73
|
o 3:1f6b4172c41e
|
o 2:639ba9dc8afc
|
o 1:5bfb5ae3faf5
|
o 0:e0890b04d1d3
and lo and behold, I find a problem with my new work. I want to start over but not lose any of the work i've done so far. So I issue the command to bring me back to 1f6b4
hg update 1f6b4
o 6:e48cc97b3508
|
o 5:9a4c73cfb4f9
|
o 4:e32af117ea73
|
@ 3:1f6b4172c41e
|
o 2:639ba9dc8afc
|
o 1:5bfb5ae3faf5
|
o 0:e0890b04d1d3
notice the @ at 3 (1f6b4)? that means the next commit will start from this point. So lets say i make three more commits, and my log looks like:
@ 9:32001847b67a
|
o 8:fb7016a799d0
|
o 7:0269a427f0d9
|
| o 6:e48cc97b3508
| |
| o 5:9a4c73cfb4f9
| |
| o 4:e32af117ea73
|/
o 3:1f6b4172c41e
|
o 2:639ba9dc8afc
|
o 1:5bfb5ae3faf5
|
o 0:e0890b04d1d3
At this point im happy, and i decide i no longer need changesets 4-6. Since they havent been pushed to my central repository, i can just get rid of them:
hg strip e32af
And the new log looks like: (remember, the revision # before the hashcode is just for convienence, like git its the hashcode which never changes)
@ 6:32001847b67a
|
o 5:fb7016a799d0
|
o 4:0269a427f0d9
|
o 3:1f6b4172c41e
|
o 2:639ba9dc8afc
|
o 1:5bfb5ae3faf5
|
o 0:e0890b04d1d3
Now I can push, and 3 new commits will be sent.
How can I accomplish this in git? This can be broken down into two questions:
- How do i have git "take me to 1f6b4" so the working directory has those files AND the next commit will branch from here. And by branch, i dont mean create a new branch, but a new head on the existing branch. So if im working on master and the head is at e48cc, how can i "go to" f16b4, which is 3 "ancestral" commits back, and the next commit will be an immediate descendant and becoming a new head on the master branch?
- Once I decided i no longer want the commit and descendants of e32af, how do i get rid of them completely? I thought i got rid of things in git before, only to see them later when i do something like
git log --all. These commits only existed here, they've never been pushed, how can I be shut of them forever?
Now there might be a better way to handle this in git, and i'm all for learning about it. However i really want to know how to accomplish this "jump to a point" and branch from there (preferably not having to create a new branch name).