DEV Community

loading...

Discussion on: I'm a Git Master, Ask Me Anything

Collapse
gonedark profile image
Jason McCreary Ask Me Anything

reset doesn't sound like the right command for what you describe. By default, reset will uncommit the changes and put them in your index. So when you go to switch branches, it's likely complaining since Git sees changes in the index.

To go back to a previous point in time, checkout is the more appropriate command.

Collapse
benaryorg profile image
#benaryorg

If I was to create a new branch and wanted it to be at exactly that commit, would I then use checkout for a detached head and then a checkout -b foobar?
Is there any better way to achieve this?

Thread Thread
gonedark profile image
Jason McCreary Ask Me Anything

You could do that.

Many forget checkout takes second argument as a reference to checkout from. So if your goal was simply to checkout a branch from an older point in time (commit abc123), you could run: git checkout -b foobar abc123