Reputation: 5617
So I decided to install the Windows version of Git locally (I do Unix web dev but also .NET dev, so seems circuitous to run Git on UNIX for my .NET projects).
For the web development work I'll just deploy it myself with FTP, but wanted to ask: is there any convenient way to have Git build a directory structure for a subset of files, such as all the files in a particular branch?
For example: say I have this web server file structure
/public_html/index.php
/public_html/config.php
/public_html/style/style.css
/public_html/style/typography.css
locally I modify only index.php and style.css
it would be nice if there was some way to "checkout" these files and have it build their full file paths. In Visual Source Safe, it actually stores all your files in the VSS database. So you can delete you working copy, and checkout a few files, and it will write them to your working directory in their appropriate directory structures. Is there something like that in GIT? if so then I could just export the modified files and upload the root folder (/public_html) to the server
Upvotes: 0
Views: 120
Reputation: 751
Check out git diff-tree
. You can use it compare the state of two commits' trees and determine what files have changed. For example:
git diff-tree --name-status -r `git merge-base master mybranch` mybranch
will show you the name and status of any files that have changed. You can also use --name-only
instead of --name-status
if you are sure that things like deleted files will still be handled correctly.
(Of course, command substitution with `` is a UNIX-shell construct; on Windows you may need to use something like FOR /F.)
You can then pass the files listed by this command to git checkout
. If you want to check files out into a separate directory, you can use the --work-tree
parameter:
git --work-tree=path/to/build checkout mybranch -- file file file...
Upvotes: 1
Reputation: 44244
You can restore the index's most recent copy of any file
with:
git checkout HEAD -- <file>
So if you deleted a file in your working directory, you could "restore" it with that command.
Upvotes: 0