git で、特定のリポジトリのバージョンを一時フォルダー内のバージョン フォルダーにチェックアウトしようとしていますが、そうすると
git checkout master~X C:/file/path/temp/versionX
エラーが発生します
error: pathspec 'temp/versionX' did not match any file(s) known to git.
問題の原因と解決方法を教えてください。
git で、特定のリポジトリのバージョンを一時フォルダー内のバージョン フォルダーにチェックアウトしようとしていますが、そうすると
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
これを試すことができます:
mkdir /file/path/temp/versionX
cd /file/path/temp/versionX
git --git-dir=/path/to/repo/.git --work-path=. checkout master~X
チェックアウトはそのようには使用できません。必要なのは git-archive(1) です。例えば:
ancestor=10
git archive --prefix="version${ancestor}" master~$ancestor |
tar xvf - -C "C:/file/path/temp"
これにより、名前付きコミットが標準出力の tarball にエクスポートされ、tar が適切な場所に解凍されます。最初は少し面倒に思えますが、次第に慣れていきます。