I need to download single file (script) from git repository. I have followed this article and manage to download file that is in root folder of the project (repository). But unfortunately, I can't figure out how to checkout file that is inside directory.
My question is how to specify path to file that is inside directory when checking out (downloading) single file? (e.g. fileA.txt from folderA in example below)
Repository example:
|-folderA
|-fileA.txt
|-fileB.txt
|-fileC.txt
|-fileD.txt
Git commands that I have run on my PC:
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
CodePudding user response:
Try saying it this way:
git checkout HEAD -- folderA/fileA.txt
(For the meaning of the double dashes, see Stack Overflow questions such as Meaning of Git checkout double dashes)