git忽略与排除vs.假设 - 不变 [英] git ignore vs. exclude vs. assume-unchanged

查看:126
本文介绍了git忽略与排除vs.假设 - 不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读过几次这些文档,但我仍然没有完全明白这些不同命令之间的差异。也许这只是我,但文档可以更清晰:



http: //git-scm.com/docs/gitignore



https://help.github.com/articles/ignoring-files



此外,很多关于此主题的评论似乎都使用了词索引,承诺,跟踪有点松散,这使得这三者之间的区别不太清楚。

p>


  • 未来将不会跟踪 .gitignore 中匹配的文件。
    (尽管它们之前可能已被追踪过)。这意味着它们
    将不会在未来的 git status 列表中显示为已更改。
    然而,未来的更改仍将与远程回购同步。换句话说,这些文件仍然是索引的,但它们并没有被追踪。
    由于 .gitignore 文件位于项目目录中,文件
    本身可以进行版本控制。


  • .git / info / exclude 中匹配的文件也不会被追踪。在
    之外,这些文件不会被远程同步,因此任何其他用户都不会以任何形式看到
    。这些文件应该是
    特定于单个用户的编辑器或工作流的文件。因为它位于 .git
    目录中,所以 exclude 文件本身不能进行版本控制。 / p>


  • 承担 - 不变运行的文件也不会显示在 git status git diff 。这看起来类似于 exclude ,因为这些文件既不是索引也不是跟踪。但是,假定 - 不变之前要提交的最后一个文件版本对于回购中的所有用户都将保持可见。




我的问题:




  1. 上述解释是否正确?如果一个文件已经在一个提交中,那么在code中匹配它的函数
    有什么不同? > .exclude 并在其上运行
    assume-unchanged ?为什么会更喜欢一种方法来
    another?


  2. 我的基本用例是,我想避免通过编译
    上的差异进行排序文件,但我仍然希望这些编译后的文件与
    同步到源文件中。会不会推出 gitignore 'd档案?如果不是,如何管理编译文件的最终部署?




  3. 感谢您的帮助。 >

    解决方案

    我将接受这是来自Junio Hamano的电子邮件答案(Git的维护者),因为我认为它比官方文档更清晰地解释了一些事情,它可以作为官方建议:


    .gitignore和.git / info / exclude是调用
    相同机制的两个UI 。 In-tree .gitignore将在项目
    成员之间共享(即,在项目中工作的每个人都应该考虑与那里的忽略模式相匹配的
    路径)。在另一个
    手中,.git / info / exclude是用于个人忽略模式(即
    你,在对该项目进行工作时,将它们视为cruft)。


    假设 - 不应该被忽略机制滥用。它是
    我知道我的文件系统操作很慢,我会向Git保证,我
    不会通过使用它来改变这些路径---这样,Git
    会每次我要求
    'git status'输出时,不必检查那里是否改变了内容。除此之外,这并不意味着什么。
    特别是,它并不是Git的承诺,Git会一直考虑
    这些路径是未修改的 - 如果Git可以确定一条路径是
    标记为假设 - 未发生变化而不会产生额外的
    lstat(2)成本,它保留报告路径
    已被修改的权利(因此,git commit - 一个可以自由地提交该更改)。



    I've read the docs on this several times over and I still don't completely get the differences between these different commands. Maybe it's just me, but the documentation could be more lucid:

    http://git-scm.com/docs/gitignore

    https://help.github.com/articles/ignoring-files

    Moreover, a lot of the commentary on this subject seems to use the words "indexed", "committed", "tracked" somewhat loosely, which makes the differences between these three less clear.

    My current (admittedly limited) understanding:

    • Files matched in .gitignore will not be tracked in the future. (Though they may have been tracked previously.) This means that they won't ever show up in a future git status list as changed. However, future changes will still be synced with remote repos. In other words, the files are still "indexed", but they are not "tracked". Because a .gitignore file is in the project directory, the file itself can be versioned.

    • Files matched in .git/info/exclude will also not be "tracked". In addition, these files will not ever be remotely synced, and thus will never be seen in any form by any other users. These files should be files that are specific to a single user's editor or workflow. Because it is in the .git directory, the exclude file can't itself be versioned.

    • Files that have had assume-unchanged run on them also don't show up in git status or git diff. This seems similar to exclude, in that these files are neither "indexed" nor "tracked". However, the last version of the file to be committed before assume-unchanged will remain visible to all users in the repo.

    My questions:

    1. Is the above interpretation correct? Please correct me.

    2. If a file has already been in a commit, what is the functional different between matching it in .exclude and running assume-unchanged on it? Why would one prefer one approach to another?

    3. My basic use case is that I want to avoid sorting through diffs on compiled files, but I still want those compiled files synced along with the source files. Will a gitignore'd file still be pushed? If not, how to manage final deployment of the compiled files?

    Thanks in advance for any help.

    解决方案

    I'm going to accept this emailed answer from Junio Hamano (the maintainer of Git) because I think it explains some things more lucidly than the official docs, and it can be taken as "official" advice:

    The .gitignore and .git/info/exclude are the two UIs to invoke the same mechanism. In-tree .gitignore are to be shared among project members (i.e. everybody working on the project should consider the paths that match the ignore pattern in there as cruft). On the other hand, .git/info/exclude is meant for personal ignore patterns (i.e. you, while working on the project, consider them as cruft).

    Assume-unchanged should not be abused for an ignore mechanism. It is "I know my filesystem operations are slow. I'll promise Git that I won't change these paths by making them with that bit---that way, Git does not have to check if I changed things in there every time I ask for 'git status' output". It does not mean anything other than that. Especially, it is not a promise by Git that Git will always consider these paths are unmodified---if Git can determine a path that is marked as assume-unchanged has changed without incurring extra lstat(2) cost, it reserves the right to report that the path has been modified (as a result, "git commit -a" is free to commit that change).

    这篇关于git忽略与排除vs.假设 - 不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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