svn学习

    xiaoxiao2025-10-29  7

    参考李龙生的博客,网址:http://blog.csdn.net/lilongsheng1125/article/details/8742200

    一、svn更新到最新的项目

    1 svn对于add操作,是把项目中原先不存在的添加进去。之后把原有的,但更新的文件,加上这些原先项目中没有的(add进去的),commit后,都进最新的项目。

    二、SVN标准库结构为:trunk、tags、branches

    1 trunk为主分支,任何时候都是最新的开发代码。

    2 branches,有Release Branches、Bug fix branches、Experimental branches

    快发布时建立Release Branches,bug fix branches用来处理将发布的bug版本,Experimental branches为实验版本

     

    3 tags  ,是里程碑的,不管是不是release,都是一个可用的版本,这里只读。

    具体使用:如从Branches To Trunk中,

    在Trunk中,右键选择Merge-》选择“Merge a range of revisions”-》URL to merge from (file:///D:xxxx/UI)---Workding Copy(<<<UI)-->next即可完成。

    4  SVN版本库,可以查看已经新建的仓库,在data文件夹->repositories里面有建立仓库的列表。

    5  linux下实例(java调用linux终端执行svn更新命令)

    war部署后,开始测试,因为war包为普通用户权限,如zhou用户的权限。

    则需要切换到zhou用户:

    su zhou

    XX

    之后checkout程序,用file形式,这样当提交时svn commit -m ''不需要输入用户名+密码

    svn checkout file:///opt/tc/csvn/data/repositories/admin

    如果不用file形式,则svn co http://ip:port/svn/admin  --username 用户名 --password  密码,这种形式,再次svn commit -m ''时需要输入用户名+密码

    首先,在linux控制台,去进行svn commit -m ''操作,去尝试看看能否成功提交。可以后,调用程序进行提交。

    特别注意:svn commit  -m 'zhou modify repoName' ,这种有空格的情况,可能会出现问题,必须是不带空格

                        svn commit  -m 'zhou-repoName'

    程序如下:

    import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Test {     /*      * 把字符串写入文件      * 输入filePath为写入文件的路径,Str为需要写入的字符串,character为字符集      *  输出为1表示写入成功,否则写入失败      */     public static int WriteStrByCharToFile(String filePath, String str,String character) {         try{             OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(filePath),"UTF-8");             out.write(str.toCharArray());             out.flush();             out.close();             return 1;         }catch(Exception e){             throw new RuntimeException(e);         }     }          public static int copy(String oldFileContent,String newFile,String charset){         try{             int flag=WriteStrByCharToFile(newFile,oldFileContent,charset);             return flag;         }catch(Exception e){             throw new RuntimeException(e);         }         }     /*      * 提交SVN版本库到远程服务器      * 输入cmdRun为运行的命令;des为目录文件夹      * 返回字符串      */     public static boolean runCmd(String cmdRun,String des){         boolean flag=false;                  try {            // Process process = Runtime.getRuntime().exec(cmd);             Process process = Runtime.getRuntime().exec(cmdRun,null,new File(des));             InputStream stderr = process.getErrorStream();             InputStreamReader isr = new InputStreamReader(stderr);             BufferedReader br = new BufferedReader(isr);             String line = null;             while ( (line = br.readLine()) != null)             System.out.println(line);             int exitValue = process.waitFor();                          System.out.println("返回值:" + exitValue);             if(exitValue==0){ //成功执行                 flag=true;             }             System.out.println("exitValue="+exitValue);                      } catch (Exception e) {             flag=false;             e.printStackTrace();             //throw new RuntimeException(e);                      }         System.out.println("flag="+flag);         return flag;     }               public static boolean submit(String cmdRun,String des,String oldFilePathContent,String newFilePath,String charset){         try{                          File file = new File(newFilePath);  //赋予文件权限             if (file.createNewFile()){                   System.out.println("File is created!");                   //Runtime.getRuntime().exec("chmod 777 /home/test3.txt");                    file.setExecutable(true);//设置可执行权限                   file.setReadable(true);//设置可读权限                   file.setWritable(true);//设置可写权限               }             int flag=copy(oldFilePathContent, newFilePath,charset); //先复制到指定的文件             System.out.println("copy   flag="+flag);             if(flag==1){//复制成功                 return runCmd(cmdRun, des); //进行提交             }else{                 return false;             }                      }catch(Exception e){             e.printStackTrace();             return false;         }              }          public static void main(String[] args) {          String contentSubmit="内容";          String username="zhou";          String repoName="repoName";                    String svnInfo="svn  commit -m '"+username+"-"+repoName+"'";                 System.out.println(svnInfo);          boolean flag= submit(svnInfo, "E:\\project\\admin", contentSubmit, "E:\\project\\admin\\trunk\\svn_access_file", "UTF-8");                       if(flag){                 System.out.println("submit成功! success");           }else{                 System.out.println("submit失败! fail ");           }              }      }

    转载请注明原文地址: https://ju.6miu.com/read-1303646.html
    最新回复(0)