Checkout
To get a work copy we have to know the location of a repository in the internet:
~/svn$ svn co http://svn.server.net/repo_name
The co subcommand has the same effect (in fact, is an alias for) subcommand checkout, so it's the same as putting:
~/svn$ svn checkout http://svn.server.net/repo_name
~/svn$ svn checkout svn://svn.server.net:port_number/repo_name
Read propset properties from a file
$ svn propget svn:keywords main.c -v
Properties on 'main.c':
svn:keywords
Rev Date
Revert last changes
$ svn revert -R .
$ svn up
Recover an old revision
This step make a local merge and the desired revision is going to be activated:
$ svn merge -r last_rev:desired_rev http://svn.server.net/repo_name/trunk
This step makes a commit to the svn.server.net:
$ svn commit -m "Revert a la revisión desired_rev"
Ignore files
In order to ignore some types of files, you have to edit the text file $(HOME)/.subversion/config and remove the comment from the line which starts with # global-ignores and add whatever type of file you want. For example, you can add *.zip and *.rar files.
Generally, a standard repository published three folders. Trunk, where major changes and the main thread of development, branches, where significant changes are made to the principal development and tags, where changes to a particular version are frozen.
We can see the status of the working copy with status or st subcommand:
~/SVN/repo_name$ svn status
Different states:
~/SVN/repo_name$ svn help status
First column: Says if item was added, deleted, or otherwise changed
' ' no modifications
'A' Added
'C' Conflicted
'D' Deleted
'I' Ignored
'M' Modified
'R' Replaced
'X' an unversioned directory created by an externals definition
'?' item is not under version control
'!' item is missing (removed by non-svn command) or incomplete
'~' versioned item obstructed by some item of a different kind
Information about work copy:
~/SVN/repo_name$ svn st -u
The last revision was done commit and its author (with -v):
~/SVN/repo_name$ svn st -u
We can see the help of one subcommand:
~/SVN/repo_name$ svn help subcommand
Uploading changes
Once you modify a file, if we run the subcommand status should show us the path to the file preceded by the letter M indicating that it was modified. To share changes with other developers need to upload the changes to the repository. This is done with the subcommand ci:
~/SVN/repo_name$ svn ci -m "Added the file foo.src"
You may not upload repository changes leave except to registered users. If this is the case you will need a username: password to upload the changes. The ci subcommand is actually an alias to commit.
Adding new files
When files or folders that did not exist in the fall copy of the repository, add to version control must be created. If we run the status subcommand after creating new files, appear preceded by a character ?, Indicating that they are unknown files or folders. To add a file or a folder and all its contents to version control add subcommand is used:
~/SVN/repo_name$ svn add archivo.src folder
When directories to version control are added, finished in ~ files are ignored, as it is assumed to be backups. The files will be added to the repository on the next commit.
Deleting files
In the same way that you can add files can be deleted:
~/SVN/repo_name$ svn delete file.src folder
This command mark to delete the file "file.src" and folder "folder/". If the file "file.src" or some files in the folfer "folder/" were modified, will not be deleted unless the --force parameter is specified. The files or folders will be deleted when the commit is done. They are aliases to delete, rm, of and remove.
The update subcommand
Every time we come back to work on a copy of a repository past some time, it is necessary to make sure that we are working on the last copy of the repository. For this run the update subcommand
~/SVN/repo_name$ svn update
At revision 106.
If new files are shown preceded by an A. There are other codes that mark different states for files and folders. Most importants are:
A Added
D Delete
U Updated
C Conflict
G Combined
A file marked Combined indicates that two or more developers modified it in different places. A file marked as Conflict indicates that two or more developers modified it on the same line. Besides the update subcommand allows us to copy us a particular revision.
~/SVN/repo_name$ svn update -r 104
At revision 104.
Viewing the last SVN revision
~/SVN/repo_name$ svn info -r HEAD
Viewing the change history
It may be useful to know that user modified a file and changes made. For this we use the subcommand log.
~/SVN/repo_name$ svn log
This will display all the comments of each of the commits made to the repository. The output of this command can be quite long, depending on the number of revisions that have the repsoitorio. To view the logs for a limited number of reviews you can use the -r argument
~/SVN/repo_name$ svn log -r 31:35
It displays only the logs of 31 to 35. For reviews see also routes the modified files you can use the -v argument is where the importance of the quality of comments shows.
Viewing the differences between versions
To see the changes made to a particular file between the current and the previous version can use svn diff, some options are:
~/SVN/repo_name$ svn diff name_file
This command shows the differences between the version of svn update and our local copy.
~/SVN/repo_name$ $svn diff -r rev1:rev2 name_file
This command shows the version of a file.
~/SVN/repo_name$ $svn cat -r rev name_file
Changing where changes are made
Sometimes, the repository root renamed, or port. However, when svn makes updates or commits, makes against the old name. It is in these cases when using the switch subcommand.
~/SVN/repo_name$ svn switch --relocate old_path new_path
Performing an export
If you want to work with files outside the svn environment, we can export to avoid copy hidden files using svn export subcommand:
~/SVN/repo_name$ svn export origin_floder destination_folder
The destination folder should not exist.
Labeling a version
Versions labeling is used to stabilize the trunk changes branch. It's like taking a picture of the project and add a name to that from that moment I know well. For example, the review will be renamed release-1.0.1.
To tag a version just run the following command:
~/SVN/repo_name$ svn copy http://svn.server.net/repo_name/trunk -r #revision http://svn.server.net/repo_name/tags/tag_name -m "comments"
If you want to tag the latest revision you can omit the -r parameter.
Using SVN we discovered that there is a better way to tag versions, which is to make first an export and then an add. This has two main advantages. The first is that the tag does not enter the svn tree immediately (just go after it does add) and the second is that it allows private tags that do not necessarily have to be added to the tree later.
Excluding files
If the directory that we are working are generated or manually add file types that do not want to climb the svn repository can generate a list that excludes them. We position ourselves in the working directory and run in command:
svn propedit svn:ignore
This will open an editor that lets you list:
* .aux
* .log
Save and update, thus the files with the extensions .log and .aux not be uploaded to the repository.
Changing SVN comments
It's very common when you work with a control system versions as subversion, wrong in the description (can be a typo, missing data or anything. We are human) when doing a commit. This is the way to change a description:
$ svn propset svn:log --revprop -r [revision_number] "New description"
Just like that, though we may have problems if the server is not configured to support the modification of the log , so you'll need to ask your administrator to enable it, but if you are the administrator, you can try the following:
1. We went into the repository directory , for example: $HOME/svn/repository/$repo
2. In the folder hooks we have to rename the file from pre-revprop-change.tmpl to pre-revprop-change:
# mv pre-revprop-change.tmpl pre-revprop-change
3. We have to change the permissions:
# chmod +x pre-revprop-change
Adding propedit properties to files for control revision
svn propset svn:keywords "Rev Date" file_name_2_add_keywords
...
### Section for configuring miscellaneous Subversion options.
[miscellany]
### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its 'status' output, and
### while importing or adding files and directories.
### '*' matches leading dots, e.g. '*.rej' matches '.foo.rej'.
global-ignores = *.rar *.zip *.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo __pycache__
# *.rej *~ #*# .#* .*.swp .DS_Store
### Set log-encoding to the default encoding for log messages
# log-encoding = latin1
### Set use-commit-times to make checkout/update/switch/revert
### put last-committed timestamps on every file touched.
# use-commit-times = yes
...
SVN relocate IP
In order to relocate the Ip od a repository:
svn switch --relocate [old URL] [new URL]
Using kompare to view differences
svn diff main.c | kompare -o -
Modifying subversion file permissions
$ svn propset svn:executable ON <executable_script>
$ svn commit