git - checkout single file under bare repository

后端 未结 3 2094
不思量自难忘°
不思量自难忘° 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:06

    I know this is ooooooooold, but I found my own use-case for this functionality and looked around for a while for a better solution to this before combining a few solutions into a simple one-liner:

    GIT_WORK_TREE=/home/dev git checkout $branch -- deploy.sh
    

    In my case, I just wanted to be able to "peek" into some of my bare repositories without unpacking the whole thing (some of them are huge). People were talking about sparse checkouts and other such things, but I just needed one-off functionality. To check out just the "Documents/Health Records" folder, for example, I would do the following:

    GIT_WORK_TREE=/tmp/my-files git checkout master -- "Documents/Health Records"
    

    And lo! There it did appear.

提交回复
热议问题