DEV Community

loading...

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

Collapse
benaryorg profile image
#benaryorg • Edited

I sometimes have trouble simply when checking out/resetting to a particular commit.
The perfect example is the git version of the Gentoo portage tree.
If I reset to some very early point in time and then go back to my origin/master, it often complains about newly added or modified files, without me actually touching anything.

Why is that?

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