git 尝试将特定提交获取到新目录时出现“未知修订版或路径不在工作树中”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23644338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"unknown revision or path not in the working tree" when trying to fetch specific commit to new directory
提问by user2893128
Total git newbie here,
这里是 git 新手,
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?
我在这里做错了什么?
采纳答案by wickstopher
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.
请记住,使用 git,您始终拥有项目历史的完整副本。如果你真的只想有那个特定的修订版(我不知道你为什么想要这个,但这似乎是你要问的),只需执行上面的命令序列并获取你想要的文件,摆脱碎屑。