【问题标题】:error: pathspec 'temp/versionX' did not match any file(s) known to git错误:pathspec 'temp/versionX' 与 git 已知的任何文件都不匹配
【发布时间】:2012-06-28 15:00:09
【问题描述】:

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

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

我得到了错误

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

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

【问题讨论】:

  • 我假设master~X 是包含您想要的文件的旧版本,而C:/file/path/temp/versionX 是您想要放置旧文件的位置。缺少两点信息:您想要哪个旧文件(相对于 Git 存储库的根目录)?您的 Git 存储库的路径是什么?
  • repo 的路径是 C:/file/path

标签: git git-checkout filepath


【解决方案1】:

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
    

【讨论】:

  • 我将其移动到的文件位于我正在工作的目录中。比如说我在文件 C:/dir/myRepo 中工作。我要检出文件的文件是 C:/dir/myRepo/oldversion/temp/versionX。我是否按照您刚才指示的方式检查文件?
  • @SSEMember:我更新了我的答案。这能回答你的问题吗?
【解决方案2】:

结帐不能这样使用。你想要的是 git-archive(1)。例如:

ancestor=10
git archive --prefix="version${ancestor}" master~$ancestor |
    tar xvf - -C "C:/file/path/temp"

这会将命名的提交导出到标准输出上的 tarball,然后 tar 将在适当的位置解压。起初看起来有点麻烦,但它会在你身上成长。

【讨论】:

  • 我希望避免存档,因为它需要 Forever 来解压缩我需要的所有内容。我目前正在做的这个工作项目是解压几百个版本的 repos,在未来的版本中,会有几千个。我希望将 repo 的版本签出到 git repo 中的不同文件,然后使用 move 命令将它们移到外面,希望它会更快。
【解决方案3】:

你可以试试这个:

mkdir /file/path/temp/versionX
cd /file/path/temp/versionX
git --git-dir=/path/to/repo/.git --work-path=. checkout master~X

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-02-04
    • 1970-01-01
    • 2022-10-12
    • 1970-01-01
    • 2013-06-01
    • 1970-01-01
    • 2015-08-28
    • 1970-01-01
    相关资源
    最近更新 更多