Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use the new `git switch` to go to a commit?

I’m starting to learn git and the recommendation was to use git switch instead of git checkout. I know how to get to a parent commit using checkout:

git checkout HEAD~3

But when using switch like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

git switch HEAD~3

I get the following error

fatal: a branch is expected, got commit 'HEAD~3'

>Solution :

git switch is stricter about what it operates on than git checkout. Whereas git checkout will create a detached HEAD if you try to check out something that is not a branch head, git switch will not, unless you explicitly signal your intent to do so by using the -d/--detach option.

git switch -d HEAD~3
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading