Command Line svn:ignore a file

This took me far too long to do, but its because no one explained it correctly to me. I’m frustrated enough that I’m not going to go back to those other websites and see if I just overlooked something. Instead I’m going to put it right here:

You don’t svn:ignore a file.

You put an svn:ignore property on the directory to ignore that filename pattern!

That makes sense, but I didn’t immediately think of that, and no source sufficiently made that point clear enough. So, if you were struggling, please grasp that concept and take a look at the commands below (which you no doubt have seen and did not think worked) and you’ll really understand what they do.

# ---------------------------------------------------------------------
#      Ignore all the .txt files in the /trunk/Blah/ directory
# ---------------------------------------------------------------------

# Go to the directory
cd trunk/Blah/              # The directory with the files

# Start editing the properties for the current directory
svn propedit svn:ignore .   # Opens an editor (SVN_EDITOR, EDITOR)

# Add the following value with a new line, save, and exit:
*.txt

# See that things worked
svn propget svn:ignore .    # So you can see the properties
svn status --no-ignore      # You should see an 'I' next to the ignored files

# Commit
svn commit -m "New Ignores" # You must commit the new property change


# ---------------------------------------------------------------------
#     Ignore a single file secret.txt in the /trunk/ directory
# ---------------------------------------------------------------------

# Go to the directory
cd trunk/

# Add just the single file to the current directories ignore list (like above)
# Note the dot at the end of the command is important
svn propset svn:ignore secret.txt .

# See that things worked
svn propget svn:ignore .    # Notice the single file was added to the list
svn status --no-ignore      # You should see an 'I' next to the ignored files

# Commit
svn commit -m "Its secret"  # You must commit the new property change

That also means in GUI programs if you can’t seem to ignore a single file that is unversioned you should instead go to the directory that file is in and (like the above) add the filename to the svn:ignore list. Cheers.

UPDATE: A few commenters have mentioned this (2 John’s below!) and it is worth adding here. If the file is already under version control or shows up as ‘M’ instead of ‘I’, then you’ll first have to svn delete the file from the repository (make a backup of it somewhere first), then svn ignore the file using the steps above and copy the file back into the repository.

search