Git:如何忽略/指定* checkout文件* [英] Git: How to ignore/specify files for *checkout*

查看:621
本文介绍了Git:如何忽略/指定* checkout文件*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我不希望跟踪.html文件,我可以将模式添加到.gitignore,它们将被忽略。我想知道我该怎么做 - 在结帐时,我怎么才能让git只检出特定类型的文件或不检出特定类型的文件?



例如,如果我不想要html文件,我可以写:

  git checkout HEAD。 --no .html 

如果存在的话:)有没有内置的方法,或者我

非常感谢您的帮助。

解决方案

如果你想打包文件进行部署,你可能不需要 - 或者想要 - 回购本身。这正是 git archive 是。一些来自手册页的例子(链接):

blockquote
git archive --format = tar --prefix = junk / HEAD | (cd / var / tmp /&& tar xf - )



创建一个包含最新提交内容的tar归档当前分支,并将其提取到/ var / tmp / junk目录中。

git archive --format = tar --prefix = git -1.4.0 / v1.4.0 | gzip> git-1.4.0.tar.gz



为v1.4.0版本创建压缩tarball。


export-ignore 的帮助下,您应该能够完全按照您的要求进行操作。属性:


export-ignore



具有export-ignore属性的文件和目录不会被添加到归档文件中。详情请参阅 gitattributes(5)




例如,要排除目录私人和文件 mine.txt secret.c ,您可以将文件放在 .gitattributes 中:

  private / export-ignore 
secret.c export-ignore

就像gitignore文件一样,您可以将这些文件放在您的存储库中的任何位置,并且可以从该目录进行操作,但从顶层开始是一个不错的选择。


If I don't want .html files tracked I can add the pattern to .gitignore and they'll be ignored. I'd like to know how I can do the converse - at checkout, how could I ask git to only checkout certain types of files or not checkout certain types of files?

For example, if I didn't want html files I could write:

git checkout HEAD . --no .html

if that existed :) Is there a way already built in, or do I just have to run something else post-checkout?

Any help is much appreciated.

解决方案

If you want to package up files for deployment, you probably don't need - or want - the repo itself. This is exactly what git archive is for. A couple examples from the manpage (linked):

git archive --format=tar --prefix=junk/ HEAD | (cd /var/tmp/ && tar xf -)

Create a tar archive that contains the contents of the latest commit on the current branch, and extract it in the /var/tmp/junk directory.

git archive --format=tar --prefix=git-1.4.0/ v1.4.0 | gzip > git-1.4.0.tar.gz

Create a compressed tarball for v1.4.0 release.

You ought to be able to get it to do exactly what you want, with the help of the export-ignore attribute:

export-ignore

Files and directories with the attribute export-ignore won’t be added to archive files. See gitattributes(5) for details.

For example, to exclude the directory private and the files mine.txt and secret.c, you could put in the file .gitattributes:

private/     export-ignore
secret.c     export-ignore

Just like gitignore files, you can put those anywhere in your repository, and they'll operate from that directory, but starting from the top level is a good bet.

这篇关于Git:如何忽略/指定* checkout文件*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆