12

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?

CharlesB
  • 86,532
  • 28
  • 194
  • 218
vairam
  • 471
  • 1
  • 11
  • 26

2 Answers2

14

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

c00kiemon5ter
  • 16,994
  • 7
  • 46
  • 48
7

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • +1 and to clarify on the "certain previous commit" (instead of HEAD): It refers to the `SHA1 ID` that can easily be found via `gitk`. If I only need to "checkout" that file to a temporary location (i.e. not reverting), then I would use the `show` subcommand: `git show 82e54378856215ef96c5db1ff1160a741b5dcd70:MyProj/proguard/mapping.txt > myproj_mapping.txt` – ef2011 Oct 14 '12 at 23:48