`

SVN Useful Commands

阅读更多

Useful Commands

Here are some examples of revision keywords in action. Don't worry if the commands don't make sense yet; we'll be explaining these commands as we go through the chapter:

$ svn diff --revision PREV:COMMITTED foo.c # shows the last change committed to foo.c

$ svn log --revision HEAD # shows log message for the latest repository commit

$ svn diff --revision HEAD # compares your working file (with local changes) to the latest version # in the repository

$ svn diff --revision BASE:HEAD foo.c # compares your "pristine" foo.c (no local changes) with the # latest version in the repository

$ svn log --revision BASE:HEAD # shows all commit logs since you last updated

$ svn update --revision PREV foo.c # rewinds the last change on foo.c # (foo.c's working revision is decreased)

$ svn info | grep URL

$ svn log -v -r9238 {Path} # to read about the exact changeset which fixed the bug at 9238

$ svn diff -r9237:9238 {path} # to see the patch itself

 

 

Undo Changes

  • Working Repository
    • svn revert --recursively
  • Undelete a file
    • get the path@revision by svn log -v
    • svn copy --revision 807 http://svn.example.com/repos/calc/trunk/real.c ./real.c
    • svn commit with log message "Resurrected real.c from revision 807, /calc/trunk/real.c."
    • or use svn merge to a single file
  • Undo a changeset in Repository on Server
Suppose you're working away happily on a working copy of /calc/trunk, and you discover that the change made way back in revision 303, which changed integer.c, is completely wrong. It never should have been committed. You can use svn merge to “undo” the change in your working copy, and then commit the local modification to the repository. All you need to do is to specify a reverse difference:

$ svn merge -r 303:302 http://svn.example.com/repos/calc/trunk U integer.c

$ svn status M integer.c

$ svn diff … # verify that the change is removed …

$ svn commit -m "Undoing change committed in r303." Sending integer.c Transmitting file data . Committed revision 350.

 

Branch

 

  • Creating a Branch
    svn copy http://svn.example.com/sample/trunk \
                  http://svn.example.com/sample/branches/{larryli}_branch  \
          -m "Creating a private branch of /calc/trunk. {Tracking Number}"
    

 

  • Creating a Working Copy of a Branch
    1. Check Out a branch
    2. Switch to a branch
      • switch command transforms an existing working copy into a different branch
      • svn switch command also takes a --revision (-r) option, so you need not always move your working copy to the “tip” of the branch.
      • switch command transforms an directory under existing working copy into a different branch
      • A superset of svn update

 

Merge

  • Sample Merge Commands
    1. $ svn merge http://svn.example.com/repos/branch1@150 http://svn.example.com/repos/branch2@212 my-working-copy
      • The first syntax lays out all three arguments explicitly, naming each tree in the form URL@REV and naming the working copy target
    2. $ svn merge -r 100:200 http://svn.example.com/repos/trunk my-working-copy
      • second syntax can be used as a shorthand for situations when you're comparing two different revisions of the same URL.
    3. $ svn merge -r 100:200 http://svn.example.com/repos/trunk
      • The last syntax shows how the working-copy argument is optional; if omitted, it defaults to the current directory.
  • Merge = Diff and Apply
  • Assume that your working copy has no local edits. When you svn update to a particular revision, the changes sent by the server will always apply “cleanly” to your working copy. The server produces the delta by comparing two trees: a virtual snapshot of your working copy, and the revision tree you're interested in. Because the left-hand side of the comparison is exactly equal to what you already have, the delta is guaranteed to correctly convert your working copy into the right-hand tree.
  • Undo
    1. svn revert --recursive
    2. delete any unversioned files or directories left behind after the revert ( using svn status to check the unversioned the files)

 

 

Best Practice

  1. Tracking Merges Manually
    • As there is no way for svn knowing the local changes done by svn merge and local modification by editting, so we need write down the specific revision number (or range of revisions) that are being merged into your branch.
  2. Previewing Merges
    • Check if the last merge happened or not from the svn log information.
    • In case the svn merge will mingle the changes to our local modification together so as to no way to revert. Please do one of the below two commands before merging.
      1. To check the differences in detail, run diff command with the same arguments you would run svn merge This way we can see what will update to our code.
      2. To get a rough information, run merge with the option --dry-run.
  3. Noticing or Ignoring Ancestry
    • Diff: ignore the ancestor by default. --notice-ancestry
    • Merge: sensitive to ancestry by default. --ignore-ancestry

 

Merging a whole Branch to Trunk

  • Get the BASE revision of the branch: svn log --verbose --stop-on-copy {branch_name}
  • Go to the trunk cd {application}/trunk
  • Get the latest repository revision and refresh local trunk so we can get the HEAD revision: svn update .
  • Merge the difference. svn merge -r branch_base:repository_HEAD http://svn.example.com/.../webapps/SampleApps/my-sample-branch
  • Check the local status: svn status
  • examine the diffs, compile, test, etc...
  • Commit the change with the specified the log message: "Merged my-sample-branch changes rBASE:HEAD into the trunk."
  • please check http://svnbook.red-bean.com/en/1.0/ch04s04.html#svn-ch-4-sect-4.1 for more details.

 

Ignore files

  • Some files created by an IDE, such as Eclipse are quite annoying. We need to take care of not checking them into svn. Below is my way to ignore those files.
    1. The files wanna to be ignored
      /home/larryli/svn/offline/webapps/TimeTrackerII>svn status .
      ?      .project
      ?      .classpath
      ?      .mymetadata
      ?      .myeclipse
      ?      META-INF/MANIFEST.MF
      ?      WEB-INF/classes
      /home/larryli/svn/offline/webapps/TimeTrackerII>ls -ltr
      
    2. Edit the file /home/larryli/.subversion>vi /home/larryli/.subversion/config
      # global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store
      global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store .project .classpath .mymetadata .myeclipse MANIFEST.MF classes
      
    3. Go back and check. It works ok.
      /home/larryli>cd /home/larryli/svn/offline/webapps/TimeTrackerII
      /home/larryli/svn/offline/webapps/TimeTrackerII>svn status .
      /home/larryli/svn/offline/webapps/TimeTrackerII>
      
  • Online Reference
    1. http://svnbook.red-bean.com/en/1.1/ch07s02.html
    2. http://svnbook.red-bean.com/en/1.1/ch07.html#svn-ch-7-sect-1.3.2

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics