我如何从一个git回购签出一个文件?


当前回答

这对我很有用。使用git和一些shell命令

git clone --no-checkout --depth 1 git.example.com/project.git && cd project && git show HEAD:path/to/file_you_need > ../file_you_need && cd .. && rm -rf project

其他回答

这对我很有用。使用git和一些shell命令

git clone --no-checkout --depth 1 git.example.com/project.git && cd project && git show HEAD:path/to/file_you_need > ../file_you_need && cd .. && rm -rf project

是的,你可以通过这个命令下载一个特定的文件

wget -o <DesiredFileName>  <Git FilePath>\?token\=<personalGitToken>

例子

wget -o javascript-test-automation.md https://github.com/akashgupta03/awesome-test-automation/blob/master/javascript-test-automation.md\?token\=<githubPersonalTone>

这听起来像是你试图从集中式版本控制中继承一个想法,而git本质上不是这样的——它是分布式的。如果你想使用git存储库,你可以克隆它。然后,您就拥有了工作树的所有内容和所有历史记录(好吧,至少是指向当前分支顶端的所有内容),而不仅仅是单个文件或单个提交的快照。

 git clone /path/to/repo
 git clone git://url/of/repo
 git clone http://url/of/repo

如果您只需要下载文件,则不需要使用Git签出。

GitHub Mate更容易做到这一点,它是一个Chrome扩展,让你点击文件图标下载它。也是开源的

你可以通过

git archive --format=tar --remote=origin HEAD | tar xf -
git archive --format=tar --remote=origin HEAD <file> | tar xf -