git 怎么跟踪空目录
【問題描述】
git和 svn不同,僅僅跟蹤文件的變動,不跟蹤目錄。所以,一個空目錄,如果里面沒有文件,即便 git add 這個目錄,另外在別處 check out 的時候,是沒有這個空目錄的。
有時候,確實需要在代碼倉庫中保留某個空目錄。比如測試時需要用到的空目錄。下面來看看如何解決:
【解決方案】
Track Empty Directories with git
git 跟蹤空文件夾
There are times when you’d like to track an empty directory within git but there’s a problem: git wont allow you to add a directory that doesn’t have a file in it. The easy solution is putting an empty stub file within the directory, and the industry standard for that stub file name is .gitkeep.
有時您想跟蹤git中的空目錄,但是有一個問題:git不允許您添加其中沒有文件的目錄。 一種簡單的解決方案是在目錄中放入一個空的存根文件,該存根文件名的行業標準是.gitkeep 。
You can quickly create the file and commit the “empty” directory from command line:
您可以快速創建文件并從命令行提交“空”目錄:
touch my-empty-dir/.gitkeep git add my-empty-dir/.gitkeep git commit -m "Adding my empty directory"注:my-empty-dir是指代空目錄路徑
The problem is simple, the solution is easy, but I wanted to highlight that .gitkeep is the industry standard.
問題很簡單,解決方案很容易,但我想強調.gitkeep是行業標準。
翻譯自:https://davidwalsh.name/git-empty-directory
上述方法注意:不要在項目的.gitignore中設置忽略.gitkeep文件,.gitkeep 是一個約定俗成的文件名并不會帶有特殊規則
總結
以上是生活随笔為你收集整理的git 怎么跟踪空目录的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Markdown编辑表格实现合并单元格、
- 下一篇: git status 不能显示中文