How can I add an empty directory to a Git repository?

后端 未结 30 2621
离开以前
离开以前 2020-11-21 04:52

How can I add an empty directory (that contains no files) to a Git repository?

30条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-21 05:08

    Many have already answered this question. Just adding a PowerShell version here.

    Find all the empty folders in the directory

    Add a empty .gitkeep file in there

    Get-ChildItem 'Path to your Folder' -Recurse -Directory | Where-Object {[System.IO.Directory]::GetFileSystemEntries($_.FullName).Count -eq 0} | ForEach-Object { New-Item ($_.FullName + "\.gitkeep") -ItemType file}
    

提交回复
热议问题