Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to checkout a single file in GIT

Tags:

git

We have developed an auto deployment tool for deploying files(ear,war and jar) in jboss server. Developers will check-in files in Visual Source safe. The auto deployment tool automatically checkouts latest files one by one specified by developer and deploys it in jboss server by using API. Now we are moving to GIT to maintain our source and other deployment files.

Does git have an option to check a single file and paths like VSS?

like image 636
vairam Avatar asked Jul 05 '11 09:07

vairam


2 Answers

You can use this

git checkout <branch-where-the-file-is> -- path/to/file/in/the/other/branch

This will retrieve the file from the other branch, to current

like image 134
c00kiemon5ter Avatar answered Sep 26 '22 15:09

c00kiemon5ter


You can retrieve a specific file from a Git repository. Something like:

git show HEAD:filename.txt

If your repository is in another directory, you can use GIT_DIR:

env GIT_DIR=/path/to/git/repo.git git show HEAD:filename.txt >filename.txt

I've shown redirecting the output to a file.

like image 27
Greg Hewgill Avatar answered Sep 23 '22 15:09

Greg Hewgill