git - 错误 : pathspec 'temp/versionX' did not match any file(s) known to git

标签 git git-checkout filepath

在 git 中,我试图将特定存储库的版本 check out 到临时文件夹内的版本文件夹中,但是当我这样做时

git checkout master~X C:/file/path/temp/versionX

我得到了错误

error: pathspec 'temp/versionX' did not match any file(s) known to git.

是什么导致了问题,我该如何解决?

最佳答案

git checkout 仅在“工作树”内运行。要做你想做的事,改变 Git 对工作树的看法。有几种不同的方法可以做到这一点:

  • 选项 1:从 Git 存储库运行

    cd /path/to/repository
    # git automatically locates the .git directory as usual
    git --work-tree=C:/file/path/temp/versionX checkout master~X
    
  • 选项 2:从目标目录运行

    cd C:/file/path/temp/versionX
    # if --git-dir is specified, Git assumes the working tree is .
    git --git-dir=/path/to/repository/.git checkout master~X
    
  • 选项 3:从其他目录运行

    cd /some/arbitrary/path
    # need to specify both the path to .git and the destination directory
    git --git-dir=/path/to/repository/.git \
        --work-tree=C:/file/path/temp/versionX \
        checkout master~X
    

关于git - 错误 : pathspec 'temp/versionX' did not match any file(s) known to git,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11247432/

相关文章:

git diff - 外部查看器 - 获取所有差异结果

git - 撤消未提交文件的 git checkout 覆盖

git - "git add file"和 "git checkout -- file"是对称的吗?

c# - Path.GetFullPath 不返回正确的路径

html - 如何禁用IE中的文件输入文本框?

git - Git 在哪里存储标签?

交互式 rebase 的 Git 问题

git - "git add submodule"上的 fatal error

git - 是否可以同时查看同一个项目的多个git分支?

python - Windows 上奇怪的路径分隔符