I'm trying to clone using HTTPs a repository (sample.com/component.git) but from a specific commit ID.
Should I fetch the repoistory, then checkout that commit ID and finally clone it, or what would be a better way?
git fetch sample.com/component.git
git checkout 9a36b9e79tbb9132c7020a5bd5694c7cefce8cff
git clone sample.com/component.git
Or
git clone sample.com/component.git 9a36b9e79tbb9132c7020a5bd5694c7cefce8cff
Try this 3 steps,
Step 1: clone the main repo:
git clone sample.com/component.git
Get inside the cloned repo cd folder_name. Now you have a working directory with latest version pulled and you want to move back to a specific commit id, here's how you can do it:
Step 2:
git reset --hard 9a36b9e79tbb9132c7 #(takes you back to that commit)
Step 3:
git clean -df #(cleans any untracked files/folders)
Git 2.49, released in 2025-03-14 added support for this with the “--revision” in the clone command.
https://git-scm.com/docs/git-clone#Documentation/git-clone.txt-code--revisionltrevgtcode
git clone --revision=683c54c999c301c2cd6f715c411407c413b1d84e --depth=1 https://github.com/gig/git.git
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With