基于unix文件权限的gitignore [英] gitignore based on unix file permissions

查看:125
本文介绍了基于unix文件权限的gitignore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个生成大量二进制文件的C项目。我尝试将源保持在源代码控制之下。但是,我希望在创建新文件时不必将其添加到gitignore文件即可忽略二进制文件。这是一个类似的沙箱,所以当我尝试新事物时,我创建了大量新的二进制文件。我可以将所有的二进制文件建立在一个目录中,或给它们一个后缀,但我不喜欢这些原因。由于GCC自动设置它生成的二进制文件的可执行位,我可以使用该标志来忽略它们吗?

解决方案

这个。如果您需要在构建过程中或运行时使用脚本,会发生什么情况,但是由于它具有可执行位,它会被意外地忽略掉。如果其他人在不了解gitignore的情况下为您的项目做出贡献,这可能会造成混乱。你最好手动添加文件(或使用bin目录)来解决这个问题。



就是说,gitignore似乎不支持基于模式的文件忽略,但您可以自动执行手动添加可执行文件的过程。



如果您的 .gitignore 文件可以被覆盖:



运行以更新您的忽略文件: find -type f -executable | sed's#^。##'> .gitignore



如果您的 .gitignore 文件应保持不变:


  1. 设置一个新的忽略文件(您现有的 .gitignore 应该仍然有效): git config core.excludesfile .auto_gitignore

  2. 运行以创建/更新忽略的文件列表: find -type f -executable | sed's#^。##'> .auto_gitignore

  3. 如果您想与其他人分享,请提交您的 .auto_gitignore ,或者添加 .auto_gitignore .git / info / exclude ,如果您没有。请注意,如果您确实分享了这些内容,那么您的协作者还必须单独执行第1步。 >如果因为你的find版本不支持 -executable 而出现错误,请用 -perm / 111 。


    I am working on a C project which generates lots of binaries. I try to keep the source under source control. However, I would like the binaries to be ignored without having to add them to the gitignore file whenever I create a new one. This is a sandbox of sorts and so I create lots of new binaries as I try out new things. I could build all my binaries in a single directory or give them a suffix, but I dislike these reasons. Since GCC automatically sets the executable bit on the binaries it produces, can I use that flag to ignore them?

    解决方案

    I recommend against this. What happens if you need to use a script in your build process or at runtime, but it's accidentally gitignored because it has the executable bit? This could especially create confusion if other people contribute to your project without knowing about the gitignore. You're best off manually adding files (or using a bin directory) to solve this problem.

    That being said, gitignore does not seem to support mode-based file ignores, but you can automate the process of manually adding files that are executable.

    If your .gitignore file can be overwritten:

    Run this to update your ignored files: find -type f -executable | sed 's#^.##' > .gitignore

    If your .gitignore file should be kept intact:

    1. Setup a new ignore file (your existing .gitignore should still work): git config core.excludesfile .auto_gitignore
    2. Run this to create/update your ignored file list: find -type f -executable | sed 's#^.##' > .auto_gitignore
    3. Commit your .auto_gitignore if you want to share it with others, or add .auto_gitignore to .git/info/exclude if you don't. Note that if you do share it, your collaborators will also have to do step 1 individually.

    Note: If you get an error because your version of find doesn't support -executable, replace it with -perm /111.

    这篇关于基于unix文件权限的gitignore的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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