git 和空文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1767165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git and empty folders
提问by deepblue
So I see Git doesn't recognize folders, or should I say when the only change between commits is addition of empty folders to the working tree they're not show in git status
after git add .
.
所以我看到 Git 无法识别文件夹,或者我应该说当提交之间的唯一变化是将空文件夹添加到工作树时,它们不会在git status
.gitignore 之后显示git add .
。
How would you handle the need to add empty folders to the working tree (for runtime storage) and have them be reflected/created when other repositories pull from the current repository (one in which the folders were added)?
您将如何处理将空文件夹添加到工作树(用于运行时存储)并在其他存储库从当前存储库(添加了文件夹的存储库)中提取时反映/创建它们的需要?
采纳答案by John Weldon
People often put an empty file as a placeholder in the folder to overcome that limitation...
人们经常在文件夹中放置一个空文件作为占位符以克服该限制...
回答by hallski
I usually put a .gitignore
in those directories as you likely want to ignore any runtime generated data anyway.
我通常将 a.gitignore
放在这些目录中,因为您可能无论如何都想忽略任何运行时生成的数据。
回答by Neo
I usually put empty .gitkeepin those folders.
我通常将空的.gitkeep放在这些文件夹中。
回答by bmargulies
You are absolutely correct. Git, like some other version control systems, does not take cognizance of empty folders or of properties of folders. Folders only exist insofar as there are file that are in them. If you want to simulate this, you need to drop placeholder files into them.
你是完全正确的。Git 与其他一些版本控制系统一样,不会识别空文件夹或文件夹的属性。文件夹仅存在于其中有文件的范围内。如果要模拟这一点,则需要将占位符文件放入其中。
回答by Dustin
You should realize that you are asking for your source control system to set up some resources that are not source, not part of your build system, but essential to the operation of your application. I would do one of the following:
您应该意识到您要求源代码控制系统设置一些不是源代码的资源,不是构建系统的一部分,但对应用程序的操作必不可少。我会执行以下操作之一:
- Make the build create the necessary directory.
- Have the application create the required directories as it runs.
- 使构建创建必要的目录。
- 让应用程序在运行时创建所需的目录。
Similarly, if the application wanted to append to a log file, it wouldn't make sense to have that logfile start out in the revision control system, would it?
类似地,如果应用程序想要附加到日志文件,那么在版本控制系统中启动该日志文件是没有意义的,是吗?
回答by hillu
Either put empty placeholder files into the folders you want git to keep track of or add instructions to create these folders to your build system if possible.
如果可能,请将空的占位符文件放入您希望 git 跟踪的文件夹中,或者添加说明以在您的构建系统中创建这些文件夹。
回答by aniruddhc
I am also facing the same issue. I think it has got to do with the way Git tracks changes. It does not track files but rather its contents. When showing the changes, commits or logs it maps the changes to specific files and shows the changes in individual files. See this video for more details Tech Talk: Linus Torvalds on gitLinus specifically gives an example about moving a function from one file to another and how git is able to track the change.
我也面临同样的问题。我认为这与 Git 跟踪变化的方式有关。它不跟踪文件,而是跟踪其内容。在显示更改、提交或记录时,它将更改映射到特定文件并显示单个文件中的更改。有关更多详细信息,请参阅此视频技术讲座:git 上的 Linus TorvaldsLinus 特别提供了一个示例,说明将函数从一个文件移动到另一个文件,以及 git 如何能够跟踪更改。
回答by meingbg
I faced this problem when trying to use git as a backup tool with support for deduplication and compression.
我在尝试使用 git 作为支持重复数据删除和压缩的备份工具时遇到了这个问题。
My solution was to create my own system. It's available on http://github.com/meingbg/store
我的解决方案是创建自己的系统。它可以在http://github.com/meingbg/store上找到
Again, my purpose was to store files, not work with code.
同样,我的目的是存储文件,而不是使用代码。