"unknown revision or path not in the working tree" when trying to fetch specific commit to new directory

StackOverflow https://stackoverflow.com/questions/23644338

  •  22-07-2023
  •  | 
  •  

Question

Total git newbie here,

I wanted to create a new folder that holds a specific commit I made. These are the steps I've taken:

git init
git add remote origin <ssh-clone-url>
git fetch origin <sha1>
git reset --hard HEAD

which gives me this error:

fatal: ambiguous argument 'HEAD': unknown revision or path not in the working tree.

What am I doing wrong here?

Was it helpful?

Solution

Your syntax for adding a remote is backwards.

...
git remote add origin <ssh-clone-url>
...

I think that the better way to do what you want to do is to pull down your master branch and cherry-pick which commit you want.

git remote add origin <ssh-clone-url>
git fetch origin master
git cherry-pick <sha1>

Remember that with git, you always have a full copy of your project history. If you really wanted to ONLY have that specific revision (I don't know why you would want this, but this seems to be what you are asking), simply execute the above command sequence and take the files that you want, getting rid of the detritus.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top