git - 在裸仓库中检出单个文件 [英] git - checkout single file under bare repository
问题描述
在服务器上,我有一个裸机存储库,它是开发过程的起源,并简化了对QA环境的部署。
因此,在 post-receive
它只是简单地做到这一点
GIT_WORK_TREE = / home / dev git checkout -f
但是随着产品变得更加复杂,还有其他一些事情应该发生。所以现在它由 deploy.sh
脚本处理,这个脚本也被存储库跟踪。所以我想做的是能够代替检出整个存储库,只检出 deploy.sh
并运行它。我认为类似的东西是可行的:
SOURCE_PATH =/ home / dev
GIT_WORK_TREE = $ SOURCE_PATH git checkout deploy.sh
$ SOURCE_PATH/deploy.sh
但它不起作用错误:
错误:pathspec'deploy.sh'与git已知的任何文件不匹配。
我做错了什么?或者是这样做是不可能的?
正如我在仅从git签出一个文件,则无法首先克隆或提取一个文件即无法签出一个文件。
但是你该文件,这意味着您可以将其内容转储到 /another/path./中
git-show HEAD:full / repo / path / to / deploy.sh> /another/path./deploy.sh
/another/path./deploy.sh
由于您是通过post-receive钩子执行的, git-show
将显示最新版本的 deploy.sh
档案。
另一种方法是尝试
GIT_WORK_TREE = $ SOURCE_PATH git checkout - path / to / deploy.sh
只检出那个文件,直接在你的工作树上。
' -
'帮助git命令了解它是一个文件,而不是像标签或另一个参数命名分支。
从 OP AlexKey 的测试中,它要求工作树至少被检出(完全)一次。
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
GIT_WORK_TREE=/home/dev git checkout -f
But as product gets more complicated there are some other things should be happening. So now it is handled by deploy.sh
script which is also tracked by repository. So what I want to do is to be able instead of checking out whole repository is to checkout only deploy.sh
and run it. I thought something like that would work:
SOURCE_PATH="/home/dev"
GIT_WORK_TREE=$SOURCE_PATH git checkout deploy.sh
$SOURCE_PATH"/deploy.sh"
But it does not work giving error:
error: pathspec 'deploy.sh' did not match any file(s) known to git.
What am I doing wrong? Or is it just impossible to do this way?
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.
这篇关于git - 在裸仓库中检出单个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!