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

后端 未结 30 2516
离开以前
离开以前 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:12

    You can save this code as create_readme.php and run the PHP code from the root directory of your Git project.

    > php create_readme.php
    

    It will add README files to all directories that are empty so those directories would be then added to the index.

     $object){
            if ( is_dir($name) && ! is_empty_folder($name) ){
                echo "$name\n" ;
                exec("touch ".$name."/"."README");
            }
        }
    
        function is_empty_folder($folder) {
            $files = opendir($folder);
            while ($file = readdir($files)) {
                if ($file != '.' && $file != '..')
                    return true; // Not empty
                }
            }
    ?>
    

    Then do

    git commit -m "message"
    git push
    

提交回复
热议问题