我需要从git存储库下载单个文件(脚本)。我遵循本文并设法下载位于项目(存储库)根文件夹中的文件。但不幸的是,我不知道如何签出目录内的文件。
我的问题是如何指定路径文件是在检查(下载)单个文件时的目录内?(例如:fileA.txt从文件夹a在下面的例子)
存储库的例子:
|-folderA
|-fileA.txt
|-fileB.txt
|-fileC.txt
|-fileD.txt
我在PC上运行的Git命令:
git clone --branch develop -n https://bitbucket.host/.../my_repository.git // clone repository with no files
cd my_repository // navigate to repository folder
git fetch
git checkout HEAD fileD.txt // successfully downloads fileD.txt file
git checkout HEAD fileC.txt // successfully downloads fileC.txt file
git checkout HEAD "folderA/fileA.txt" // error: pathspec 'folderA/fileA.txt' did not match any file(s) known to git
git checkout HEAD "/folderA/fileA.txt" // fatal: Invalid path '/folderA': No such file or directory
试着这样说:
git checkout HEAD -- folderA/fileA.txt
(关于双破折号的含义,请参见Stack Overflow问题,如Git checkout双破折号的含义)