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.
I build things with my hands. The human behind Shift - https://laravelshift.com, master of Git - https://gettinggit.com, and author of "BaseCode" - https://basecodefieldguide.com
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.
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?
I build things with my hands. The human behind Shift - https://laravelshift.com, master of Git - https://gettinggit.com, and author of "BaseCode" - https://basecodefieldguide.com
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
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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?
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.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 acheckout -b foobar
?Is there any better way to achieve this?
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 (commitabc123
), you could run:git checkout -b foobar abc123