Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I check if a file/folder is already committed to svn ? I have a shell script where I want to ensure that the file/folder selected by user for check-in isn't already committed. For eg if I try to check-in a folder that's already committed using

svn add myfolder

I get the following warning:

svn: warning: 'myfolder' is already under version control

share|improve this question
up vote 4 down vote accepted

Use the return code of svn info. It's 0 if under version control, non-zero otherwise.

My shell displays non-zero return codes after a command, so it looks like this:

$ svn info trunk
Path: trunk
URL: https://(...)/trunk
Repository Root: https://(...)
Repository UUID: 651713a4-5a46-7e42-a99e-f31e79777eab
Revision: 213
Node Kind: directory

$ touch foo
$ svn info foo 
foo:  (Not a versioned resource)

svn: A problem occurred; see other errors for details

rc: 1

How you'd do it in a bash script (similar in other shells), with suppressing info output:

svn info <filename> 1>/dev/null 2>&1
echo $?
share|improve this answer
As a one-liner in bash: [[ $(svn info $file 1>/dev/null 2>&1) == 0 ]] && echo "$file is under version control – derFunk Apr 17 '15 at 9:31
@derFunk Or just (svn info $file 1>/dev/null 2>&1) && echo "$file is under version control". Plus the line where you define file. – Daniel Beck Apr 17 '15 at 9:34

I'm using this:

if [ $(svn status $file | awk '{ print $1 }') == "?" ]; then
    echo "File is not under version control"

This way you can also query different svn status codes which can be seen here:

share|improve this answer

I wanted to solve a similar problem: As part of a script which generated a file, automatically add it to subversion if this had not been done previously.

I found the following worked:

if ! svn info ${file} 1>/dev/null 2>&1 ; then
  svn add ${file}

Testing exit values in Bash led me to this answer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.