On the production there is a folder "DIRX".

There is a repository with the structure:

MainDIR -dir0 -dir1 -dir2 

How to get the contents of the folder MainDIR / dir1 in the production folder DIRX using git?

With SVN, this is done like this:

 cd DIRX svn co //path/dir/ . 

With the git it turned out to pick up the folder along with its creation *, it was not possible to pick up the contents separately.

* so it turned out like this:

 DIRX/dir1/ 

Also, if such a solution exists, how then to update (pick up the latest changes in) this folder?

    1 answer 1

    Pre-notification: I proceed from the assumption that you have the dir1 directory in the repository, and not MainDIR/dir1 . if, after all, MainDIR/dir1 , then replace the last parameter of the git program and increase by one the value of the strip option of the tar program.


    For example, like this: using git archive create an archive from the necessary files / directories, and then unzip them in the right place, “cutting off” the necessary number of “extra” components in the path to the files / directories:

     $ git archive --remote=url-репозитория ветка dir1 | tar -x --strip=1 -C /путь/к/DIRX 
    • url-репозитория - the url of the repository in any form understood by the git program.
    • ветка - there may be, for example, master .
    • dir1 - the last arguments to the archive command can be passed to the paths to the files, directories that will be included in the created archive.
    • --strip=1 is the option of the tar program that cuts the path components when unpacking. for example, the archive contains dir/subdir/file . if you do not specify the option, that is how it will be unpacked. if you specify --strip=1 , then subdir/file will be --strip=2 , and if --strip=2 , then only file .
    • -C /путь/куда/распаковывать - this option in the case when you do not want (or for some reason can not) pre-make cd /путь/куда/распаковывать .

    You can update this directory with the same command.