git - checkout single file under bare repository

后端 未结 3 2042
不思量自难忘°
不思量自难忘° 2021-02-19 07:47

On the server I have bare repository which is origin for development process and to simplify deployment to QA environment.

So in post-receive it simply does

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 08:31

    As I explain in "checkout only one file from git", you cannot checkout just one file without cloning or fetching first.

    But you git show that file, which means you can dump its content into a /another/path./deploy.sh file, and execute that file.

    git-show HEAD:full/repo/path/to/deploy.sh > /another/path./deploy.sh
    /another/path./deploy.sh
    

    Since you execute that from a post-receive hook, the git-show will show the latest version of the deploy.sh file.


    The other alternative would be try

     GIT_WORK_TREE=$SOURCE_PATH git checkout -- path/to/deploy.sh
    

    And checkout only that file, directly in your working tree.

    The '--' help the git command to understand it is a file, not another parameter like a tag or a named branch.

    From the OP AlexKey's test, it requires that the working tree has been checked out (fully) at least once.

提交回复
热议问题