Skip to content

Instantly share code, notes, and snippets.

@brunoguerra
Last active July 2, 2024 06:14
Show Gist options
  • Save brunoguerra/3b1a1fb3d4e076bd8fa1d00046ceaed3 to your computer and use it in GitHub Desktop.
Save brunoguerra/3b1a1fb3d4e076bd8fa1d00046ceaed3 to your computer and use it in GitHub Desktop.
GIT FETCH SPECIFIC COMMIT

make a new blank repository in the current directory

git init

add a remote

git remote add origin url://to/source/repository

fetch a commit (or branch or tag) of interest

Note: the full history of this commit will be retrieved

git fetch origin # SHA #

reset this repository's master branch to the commit of interest

git reset --hard FETCH_HEAD

@shqear93
Copy link

Man, you saved me, thanks

@sergej-koscejev
Copy link

GitHub supports fetching arbitrary SHAs if e.g. a branch was force-pushed and you want to fetch the state before the forced push. Maybe this case counts as "advertised object SHA".

The commit hash must not be abbreviated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment