"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
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top