git解决空文件夹无法提交

Posted zhizou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了git解决空文件夹无法提交相关的知识,希望对你有一定的参考价值。

public class Gitsvn {
        public static final String GITSVN = ".keep";

        private static void check(File path) throws Exception
        {
            File[] files = path.listFiles();
            if (files.length == 0) {

                System.out.printf("+ %s/.keep
", path.getAbsolutePath());
                mark(path.getAbsolutePath());
            } else {
                if (files.length != 1 || !files[0].getName().equals(GITSVN)) {
                    for (int i = 0; i < files.length; i++) {
                        if (files[i].getName().equals(GITSVN)) {
                            System.out.printf("- %s
", files[i].getAbsolutePath());
                            files[i].delete();
                        }

                        if (files[i].isDirectory()) {
                            try {
                                check(files[i]);
                            } catch (Exception e) {

                            }
                        }
                    }
                }
            }
        }

        private static void clear(File path, String target) throws Exception
        {
            File[] files = path.listFiles();

            for (int i=0; i<files.length; i++)
            {
                if(files[i].getName().equals(target))
                {
                    System.out.printf("- %s
", files[i].getName());
                    files[i].delete();
                }
                else if (files[i].isDirectory())
                {
                    try
                    {
                        clear(files[i], target);
                    }
                    catch (Exception e)
                    {

                    }
                }
            }
        }

        public static void mark(String path)
        {
            File file = new File(path + "/" + GITSVN);
            try
            {
                file.createNewFile();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }

        public static void main(String[] args)
        {
            String home = System.getProperty("user.dir");
            File file = new File(home);

            try
            {
                if(args.length==2 && args[0].equals("-clean"))
                {
                    clear(file, args[1]);
                }
                else
                {
                    check(file);
                }
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
        }

}

 

以上是关于git解决空文件夹无法提交的主要内容,如果未能解决你的问题,请参考以下文章

git无法上传空文件夹分析

git提交空目录

git-tfs clone 创建空文件夹

git提交不上去

黑猴子的家:Git 提交空文件夹

IntelliJ IDEA 2021.1 使用git提交代码时,提交信息无法输入中文问题解决方法