Add all unversioned files to Subversion using one Linux command

前端 未结 11 1691
滥情空心
滥情空心 2020-12-23 09:24

Sometimes I include many files in different directories in my project. For now I am adding all files one by one to my project before commit. Is there any Linux terminal comm

相关标签:
11条回答
  • 2020-12-23 09:32

    Adds any file with a question mark next to it, while still excluding ignored files:

    svn status | grep -v "^.[ \t]*\..*" | grep "^?" | awk '{print $2}' | xargs svn add
    svn commit
    

    http://codesnippets.joyent.com/posts/show/45

    0 讨论(0)
  • 2020-12-23 09:34

    An approach using a Perl one-liner to add all files shown with a question mark by "svn st" would be:

    svn st | perl -ne 'print "$1\n" if /^\?\s+(.*)/' | xargs svn add
    

    This should also work with space characters in file names.

    0 讨论(0)
  • 2020-12-23 09:38

    This shell script, recursively examines (svn status) directories in your project, removing missing files and adding new files to the repository. It is some sort of "store into the repository the current snapshot of the project".

    if [ $# != 1 ]
    then
        echo  "usage: doSVNsnapshot.sh DIR"
        exit 0
    fi
    
    ROOT=$1
    
    for i in `find ${ROOT} -type d \! -path "*.svn*" `
    do
    
        echo
        echo "--------------------------"
        ( cd $i ; 
        echo $i
        echo "--------------------------"
    
    
        svn status | awk '  
                /^[!]/ { system("svn rm " $2) }
                /^[?]/ { system("svn add " $2) }
            '
        )
        echo
    
    done
    
    0 讨论(0)
  • 2020-12-23 09:40

    By default, the svn add command is recursive. Just point it at the top-level directory of your project and it should add any file not already there.

    You may want to include the --force option, though keep in mind that this will also add files which are otherwise excluded due to svn:ignore (if you don't use svn:ignore, then you won't have any issues).

    0 讨论(0)
  • 2020-12-23 09:45

    None of you guys are fully correct I spend a whole night to fix it and it's running properly in my jenkins:

    svn status | grep -v "^.[ \t]*\..*" | grep "^?[ \t]*..*" | awk '{print $2}' | sed 's/\\/\//g' | sed 's/\(.*\)\r/"\1"/g' | xargs svn add --parents
    svn commit
    
    1. status
    2. remove .svn
    3. find ? at the line begining to determine whether it is unversioned (modify it to | grep "^?[ \t]*.*cpp" | will only add cpp)
    4. remove ? (one of the above thread memtion the problem of awk, you may try to use tr or sed instead)
    5. replace splash to linux splash(optional, cygwin need)
    6. enclose line with quote
    7. call xargs(you should add --parent to make sure mid level sub folders are also added if you try to filter cpp or certain file pattern)
    0 讨论(0)
  • 2020-12-23 09:47

    I haven't used SVN. But the following should work.

    svn add foo/bar.file bar/foo.file
    

    This should add file bar.file in the foo directory and foo.file existing in the bar directory.

    And svn add foo should add all files in foo to the server. The "recursive" flag is set by default.

    And to add all files in a directory except for a few (like the files starting/ending with keywords tmp, test, etc.), I don't think there is a cleaner/simpler way to do it, and better write a shell script that does this.

    0 讨论(0)
提交回复
热议问题