Skip to content

Instantly share code, notes, and snippets.

@stemar
Last active April 13, 2021 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stemar/9273f7dcad469787b8da6a88155fc4d8 to your computer and use it in GitHub Desktop.
Save stemar/9273f7dcad469787b8da6a88155fc4d8 to your computer and use it in GitHub Desktop.
SVN commands and workflow

SVN workflow

http://svnbook.red-bean.com/en/1.6/svn-book.html


Workflow

Check before working:

cd ~/project/branches/develop
svn update
svn status
svn diff

Work on develop branch...

Check your working copy:

svn status
svn diff

Commit to develop branch:

svn add filename
svn delete filename
svn update
svn commit -m "Message"

Merge to trunk and diff:

cd ~/project/trunk
svn update
svn merge ^/branches/develop
svn diff

Check conflicts and resolve:

svn update
svn resolved filename

Commit to trunk:

svn commit -m "Message"

Show log:

svn log

Remote home directory

  • ssh expands the remote $HOME directory when the command is wrapped in single quotes:
    • ssh username@domain.com 'ls -l $HOME' correctly expands to remote home directory.
    • ssh username@domain.com "ls -l $HOME" incorrectly expands to local home directory.
  • The svn+ssh:// protocol does not expand the remote $HOME directory so we have to use a bash constant:
    SVN_SSH_HOME=$(ssh username@domain.com 'echo $HOME')
    

Keywords

  • HEAD: the latest revision in the repository of the directory being considered (whether a local working copy or a repository URL).
  • BASE: the revision number of an item in a working copy. If the item has been locally modified, this refers to the way the item appears without those local modifications (i.e. the pristine copy immediately after the checkout or most recent update).
  • COMMITTED: the most recent revision prior or equal to BASE in which an item changed.
  • PREV: the revision immediately before the last revision in which an item changed, or COMMITTED - 1.

Create a local repository

mkdir -p ~/svn_repo
svnadmin create ~/svn_repo/project
svn import ~/project-to-import file://$HOME/svn_repo/project/trunk -m "Initial import of project."

Create a remote repository using ssh

  • rsync source path: don't forget trailing slash!
ssh username@domain.com 'mkdir -p ~/svn_repo && svnadmin create ~/svn_repo/project'
rsync -av ~/project-to-import/ username@domain.com:~/project-to-import
ssh username@domain.com 'svn import ~/project-to-import file://$HOME/svn_repo/project/trunk -m "Initial import of project."'

Checkout

svn checkout file://$HOME/svn_repo/project/trunk ~/project/trunk
svn checkout http://domain.com/svn_repo/project/trunk ~/project/trunk
svn checkout svn+ssh://username@domain.com$SVN_SSH_HOME/svn_repo/project/trunk ~/project/trunk
cd ~/project/trunk
svn info
svn update

Branches

Assuming:

file://$HOME/svn_repo/project/
├── trunk
├── branches
│   ├── develop
│   └── ...
└── tags
    └── ...

Mirroring working copy dirtree:

~/project/
├── trunk
├── branches
│   ├── develop
│   └── ...
└── tags
    └── ...

Create a branch from trunk:

cd ~/project/trunk
svn copy ^/trunk ^/branches/develop --parents -m "Message"
svn copy file://$HOME/svn_repo/project/trunk \
         file://$HOME/svn_repo/project/branches/develop --parents -m "Message"
svn copy http://domain.com/svn_repo/project/trunk \
         http://domain.com/svn_repo/project/branches/develop --parents -m "Message"
svn copy svn+ssh://username@domain.com$SVN_SSH_HOME/svn_repo/project/trunk \
         svn+ssh://username@domain.com$SVN_SSH_HOME/svn_repo/project/branches/develop --parents -m "Message"

Then checkout the new branch:

svn checkout ^/branches/develop ~/project/branches/develop
svn checkout file://$HOME/svn_repo/project/branches/develop ~/project/branches/develop
svn checkout http://domain.com/svn_repo/project/branches/develop ~/project/branches/develop
svn checkout svn+ssh://username@domain.com$SVN_SSH_HOME/svn_repo/project/branches/develop ~/project/branches/develop
cd ~/project/branches/develop

Delete a branch:

svn delete ^/branches/develop -m "Message"
svn delete file://$HOME/svn_repo/project/branches/develop -m "Message"
svn delete http://domain.com/svn_repo/project/branches/develop -m "Message"
svn delete svn+ssh://username@domain.com$SVN_SSH_HOME/svn_repo/project/branches/develop -m "Message"
rm -rf ~/project/branches/develop

List the current branch:

svn info

List all branches:

svn list ^/branches
svn list file://$HOME/svn_repo/project/branches
svn list http://domain.com/svn_repo/project/branches
svn list svn+ssh://username@domain.com$SVN_SSH_HOME/svn_repo/project/branches

Status

Compare your working copy to BASE:

svn status

Compare your working copy to HEAD:

svn status -u

Diff

Show file differences between your working copy and BASE:

svn diff

Show file differences between your working copy and HEAD:

svn diff -r HEAD

Show file differences between BASE and HEAD:

svn diff -r BASE:HEAD

Show file differences between two revisions:

svn diff -r n:m

Show file differences between two branches:

svn diff ^/trunk ^/branches/develop

Compare a file to another revision:

svn diff -r n:m filename

Compare a file to another branch:

svn diff ^/trunk/filename ^/branches/develop/filename

Revert

Undo your working copy changes before commit:

svn revert -R .

Update

svn update will display conflicts and ask to select resolution.

Update with HEAD:

svn update

Update with a previous revision:

svn update -r 3

Commit

Add or delete files:

svn add filename
svn delete filename

Commit all your working copy changes to the repository:

svn update
svn commit -m "Message"

Commit one file your working copy changes to the repository:

svn update
svn commit filename -m "Message"

Log

View the log:

svn log

Merge

Merge to local trunk:

cd ~/project/trunk
svn update
svn merge ^/branches/develop
svn merge file://$HOME/svn_repo/project/branches/develop
svn merge http://domain.com/svn_repo/project/branches/develop
svn merge svn+ssh://username@domain.com$SVN_SSH_HOME/svn_repo/project/branches/develop
svn diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment