如何使用 git 只检出具有给定文件扩展名的文件及其父文件夹?
我们将在 TeamCity 下运行的 Ant 构建脚本中使用它。
We would be using this inside an Ant build script running under TeamCity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我所做的并且效果很好。我只需要编辑项目中的 markdown(扩展名 .md)文件。
你应该看到:
完成!
现在您可以像以前一样使用这些文件
你已经检查了一切,包括对遥控器进行拉动和推送
它只会更新您签出的文件,而不会删除其余文件。
This is what I did and it works pretty well. I had a need to edit only the markdown (extension .md) files within a project.
you should see:
done!
Now you can work with these files just as you would as if
you had everything checked out, including doing a pull and push to a remote and
it will only update the files that you checked out without deleting the rest.
(通过“签出”,我假设您的意思是 git 术语中的“克隆” - 即您当前没有存储库的副本,并且需要从远程存储库获取一些文件。)
简短的答案是您可以' t。
在有一些限制的情况下,您可以在 git 中进行浅克隆(仅获取最后几个版本),但您不能轻松地进行窄克隆(仅获取某些部分)存储库,例如一个子目录,或仅匹配特定条件的文件)。
在某种程度上,这实际上是 git 作为分布式版本控制系统的一个功能:当您克隆了一个存储库时,您知道您已经获得了完整的历史记录、所有分支以及完全处理代码所需的一切独立的。
当然,有多种方法可以解决这个问题,例如:
tar -x --wildcards --no-anchored '*.whatever'
(By "checkout" I assume that you mean "clone" in git terminology - i.e. you currently don't have a copy of the repository, and need to get some files from a remote repository.)
The short answer is that you can't.
You can, with some restrictions, do shallow clones in git (only getting the last few versions), but you can't easily do narrow clones (grabbing only some parts of the repository, such as one subdirectory, or only files that match particular criteria).
In a way, this is actually a feature of git as a distributed version control system: when you've cloned a repository you know that you've got the complete history, all the branches, and everything you need to work on the code completely standalone.
There are, of course, various ways around this, for example:
git archive --remote=<repo>
to fetch a tar archive of the remote repository, and pipe that totar -x --wildcards --no-anchored '*.whatever'