git and empty folders

随声附和 提交于 2019-12-17 15:53:47

问题


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 ..

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)?


回答1:


People often put an empty file as a placeholder in the folder to overcome that limitation...




回答2:


I usually put a .gitignore in those directories as you likely want to ignore any runtime generated data anyway.




回答3:


I usually put empty .gitkeep in those folders.




回答4:


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.




回答5:


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:

  1. Make the build create the necessary directory.
  2. 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?




回答6:


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.




回答7:


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 git Linus specifically gives an example about moving a function from one file to another and how git is able to track the change.




回答8:


I faced this problem when trying to use git as a backup tool with support for deduplication and compression.

My solution was to create my own system. It's available on http://github.com/meingbg/store

Again, my purpose was to store files, not work with code.



来源:https://stackoverflow.com/questions/1767165/git-and-empty-folders

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!