Subversion, svn

From Andreida

Deciding which Source Management Tool to use?


see also

get svn

You need a working svn, so with Debian you would do something like

apt-get install subversion

while with Windows you get one of the Windows binaries:

  • SilkSVN for just the command line, as far as I know
  • TortoiseSVN to get a graphical interface in your explorer (or Total Commander), command line still available but has to be selected during install (I ALWAYS install the command line too, some things are just more understandable when done on the command line)
  • VisualSVN for an interface inside Visual Studio
  • Cirata which I have no idea about
  • some more clients

svn, creating a repository locally

  • either use the command line in Linux
svnadmin create /var/svn/repo01
  • or use the command line in Windows
svnadmin create d:\data\repos\svn\test
  • Test it under Linux
svn list /var/svn/repo01
  • Test it under Windows
svn list file:///D:/data/repos/svn/test/

As you see, svnadmin uses local paths and svn uses remote paths. You will not use svnadmin often or even not at all, so it is not that important to you.

If you are using TortoiseSVN you can skip the whole thing, just

  • use your Total Commander or File Explorer to show the folder where you want the new repository,
  • create an empty folder like "test2",
  • go inside the empty folder,
  • right click inside and select "TortoiseSVN / Create repository here".
  • done. :-)

using a local repository

  • Go to your working folder (you have one, right?), something like "C:\work".
  • with Linux
svn checkout /var/svn/repo01 testX01
  • with Windows
svn checkout file:///D:/data/repos/svn/test/ testX01
  • checkout with TortoiseSVN
    • right-click the empty area and
    • select "SVN Checkout..."
    • URL of repository: file:///D:/data/repos/svn/test/
    • Checkout directory: C:\work\test

Adding existing project to own trunk inside (new) local repository

  • go the folder where the new repository will be created
cd /D d:\data\repos\svn
  • create the new repository
svnadmin create tutorials
  • check it
svn list file:///d:/data/repos/svn/tutorials
  • think about the tree/dir structure we want
/
 ue4
    GDPwUE
          trunk
          branches
          tags
  • Create this structure in the repository:
svn mkdir file:///d:/data/repos/svn/tutorials/ue4/GDPwUE/trunk -m "creating trunk dir for GDPwUE" --parents
svn mkdir file:///d:/data/repos/svn/tutorials/ue4/GDPwUE/branches -m "creating branches dir for GDPwUE"
svn mkdir file:///d:/data/repos/svn/tutorials/ue4/GDPwUE/tags -m "creating tags dir for GDPwUE"
  • import the project to trunk (the content of GDPwUE will be inside trunk)
svn import C:\work\tutorials\ue4\GDPwUE file:///d:/data/repos/svn/tutorials/ue4/GDPwUE/trunk -m "initial import of GDPwUE"
  • now move the original GDPwUE somewhere else for safekeeping, in case you did something wrong
  • checkout the project
cd /D c:/work/tutorials
svn checkout file:///d:/data/repos/svn/tutorials/ue4/GDPwUE/trunk GDPwUE
cd GDPwUE
svn log
svn log -q
svn log -v
tree

svn, What you normally need

  • get current version
svn up
  • commit your changes
svn commit -m '<description>'


Get an idea about your svn-urls:

svn info

Create a branch from an existing Url: (use ", not ' with Windows)

svn copy https://192.168.20.1:3690/svn/src/c++/YourProject/trunk \
https://192.168.20.1:3690/svn/src/c++/YourProject/branches/YourFixForBadError \
-m 'we have a bad bad error'

You just created the branch in the repository, now get it:

svn up

Do your changes and fixes, then

svn status

do get an idea which files you added or changed. If you added files, add them to subversion with

svn add <file>

Commit all your changes with (" for Windows)

svn commit -m '<description>' 

if it took a lot of time for all this, get the current trunk into your branch:

svn merge <url-to-trunk>
svn status
svn diff
svn commit


Go to your trunk

cd <whatever>src/c++/yourProject/trunk

if you are unsure, what you did:

svn diff <trunk-url> <branch-url>

merge the branch into the trunk:

svn merge <url-to-branch>
svn status
svn commit -m '<description>'

ignore files or directories (without /)

svn propedit svn:ignore .

undo an "add"

svn revert --recursive <folder>
svn revert --recursive .

other project as subdirectory, internal link

If you have a repository with the path

/c++/_internal

and you in some project like

/c++/myProject

you want to use the first one without using ../ you can use the following (the last . is important too, Windows: use " instead of ')

svn propset svn:externals '^/c++/_internal _internal' .
svn up

svn, commit a message with an apostrophe

What will not work:

svn commit -m 'user's test'

What should work

svn commit -m "user's test"

What we want to show here

 svn commit -m 'user'\''s test' 

So we have three parts in the commit

'user'
\'
's test'

svn, ignore

There are three ways to ignore files/directories:

  • in your repository you set ignores for this directory and all below and it just works, no need to think about it
svn propset svn:global-ignores "Intermediate" .
  • in your repository you set ignores for this directory and if you want it for all EXISTING sub-directories too you use "--recursive":
svn propset svn:ignore "Intermediate" . 
  • in your configuration file for your svn installation in the "global-ignores" section you set it for all repositories at once, but have it only locally.

So... in nearly all cases you want either "svn:global-ignores" or "svn:ignore".

Reason? You want it to work for everyone who checks out the repository or - how it is normal for large projects - parts of the repository. A new member of the team should not add "Intermediate" to the repository because he was not told yet not to do it. He will just not see it when working with svn normally.

How do you do it and keep sane?

Create a file ".svnignore" with content like:

Binaries
Intermediate
Saved
DerivedDataCache
.vs
.vsconfig
*.sln

Create a script like "use-ignore-file.cmd" with content like:

svn propset svn:global-ignores -F .svnignore .

Add both files to svn. After using the script you will probably have to use "svn update" before you can do other stuff.