zoukankan      html  css  js  c++  java
  • JGit AddCommand无效的问题

    参考:https://blog.csdn.net/luckyrocks/article/details/107671468

    https://stackoverflow.com/questions/45913082/jgit-addfilepattern-not-working-for-my-absolute-path-to-a-file

    问题:我在windows 使用jGit操作git ,git add 文件没有添加到git管理。git目录是D:\aa ,我想添加D:\aa\bb文件夹及其所有子文件

                AddCommand addCommand = git.add();
                addCommand.addFilepattern("D:\aa\bb").call();\无效
    

      正确用法:使用相对路径,如果有子目录,使用  /   作为路径分隔符

                AddCommand addCommand = git.add();
                addCommand.addFilepattern("bb").call();
    

      原因:addCommand 暂不支持 * ,filePath/. 等递归操作,且只支持相对路径和  /  作为分隔符的路径

    JGit 提交完整代码,执行前先确定当前环境git pull 能不能成功,有没有冲突,如果想使用jGit做冲突处理,请参考其他代码。

            Git git;
            try {
                git = new Git(new FileRepository(LOCALGITFILE));//对应值为D://aa/.git 
                PullResult pullResult = git.pull().setCredentialsProvider(new UsernamePasswordCredentialsProvider(USER, PASSWORD)).call();
                System.out.println(pullResult.toString());
                AddCommand addCommand = git.add();
                addCommand.addFilepattern("bb").call();//对应路径为D://aa//bb
                git.commit().setMessage("java commit").call();
                Iterable<PushResult> pushResults = git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(USER, PASSWORD)).call();
                pushResults.forEach(pushResult -> {
                    System.out.println(pullResult.toString());
                });
            } catch (IOException | GitAPIException e) {
                e.printStackTrace();
            }
    

      

  • 相关阅读:
    CodeForces 734F Anton and School
    CodeForces 733F Drivers Dissatisfaction
    CodeForces 733C Epidemic in Monstropolis
    ZOJ 3498 Javabeans
    ZOJ 3497 Mistwald
    ZOJ 3495 Lego Bricks
    CodeForces 732F Tourist Reform
    CodeForces 732E Sockets
    CodeForces 731E Funny Game
    CodeForces 731D 80-th Level Archeology
  • 原文地址:https://www.cnblogs.com/BigWrite/p/13853094.html
Copyright © 2011-2022 走看看