2

I made a simple script to have my current revision copied to clipboard. At least that's what I thought I did after I used this post: Current Subversion revision command

enter image description here

But as you can see in the image, what the command gives is not the revision number of the current branch at all. So how do I really get the revision number of the branch via a command?

1
  • a lot of the confusion comes from the fact that after you committed a new revision, your work area will still reside on the old revision number, whereas the new revision number will only be in your repository, hence the different numbers when you use svnversion. Do a svn update after svn commit and svnversion is your friend
    – Mike
    Mar 8 at 17:45

3 Answers 3

2

So the actual command that I'm using and that is the only one that works for me to get current revision is this one:

svn info --revision HEAD --show-item last-changed-revision
2
  • 1
    I think there's a typo. Shouldn't the command be: svn info --revision HEAD --show-item last-changed-revision Jun 18, 2022 at 9:22
  • I've updated it. Jan 22 at 18:18
1

tl;dr:

Use the COMMITTED alias instead of HEAD

Details:

The most direct way to get the revision at the "tip" of the current branch is to use the COMMITTED alias instead of HEAD (it's amazing that I wasn't aware of the COMMITTED alias for so long).

Git uses HEAD to refer to the tip of the current branch.

Subversion uses HEAD to refer to the tip of the entire repository - not the current branch for the workspace. Subversion uses the COMMITTED alias for that.

svn info shows both pieces of information:

        C:>svn info
        Path: .
        Working Copy Root Path: --elided--
        URL: svn:--elided--
        Relative URL: ^--elided--
        Repository Root: svn:--elided--
        Repository UUID: dcba06d3-f740-481d-b6cf-80debfe3ba96
1) ---> Revision: 40018
        Node Kind: directory
        Schedule: normal
        Last Changed Author: mike
2) ---> Last Changed Rev: 40013
        Last Changed Date: 2022-06-15 08:06:48 -0700 (Wed, 15 Jun 2022)
  • #1 is the tip of the repository
  • #2 is the tip of the current workspace's branch

If you just want the commit ID:

C:>svn info -r HEAD --show-item revision
40018

C:>svn info -r COMMITTED --show-item revision
40013

And if you want the log information, note that asking for HEAD will give you nothing (unless HEAD == COMMITTED). Asking for COMMITTED will show exactly what you want:

C:>svn log -r HEAD
------------------------------------------------------------------------

C:>svn log -r COMMITTED
------------------------------------------------------------------------
r40013 | mike | 2022-06-15 08:06:48 -0700 (Wed, 15 Jun 2022) | 17 lines

    -- remainder of log message elided --

------------------------------------------------------------------------
0

If you don't specify a target for svn info then it defaults to '.' which is gonna be your working copy path.

Also from svn help info:

TARGET may be either a working-copy path or a URL. If specified, REV determines in which revision the target is first looked up; the default is HEAD for a URL or BASE for a WC path.

This means, if you want the HEAD revision then you have to specify the URL of your repository:

svn info URL-of-repo --show-item revision

Note that this is only how svn info works by default, you can always specify your own revision argument:

svn info --revision HEAD --show-item revision

On the other hand you can also use svn status -u to get the HEAD revision like so:

svn status -u | awk '{ print $NF }'

Here's the result of these commands on my machine

enter image description here

6
  • Neither of these works, it returns different revision than what I see in tortoise git. Nov 8, 2019 at 9:51
  • Tortoise git? Also if they return a different revision than what you need, then I probably misunderstood the question. By current revision do you mean the HEAD revision or something else? Nov 8, 2019 at 15:27
  • I want the revision number that is highligted, and that's the one that I pass to testers to fetch the commit that I just created. My current workflow is commit, then go to SVN Log and select "Copy -> Revisions". I wanted to speed that up. Nov 8, 2019 at 16:57
  • I found that this works: --revision HEAD --show-item last-changed-revision But why this and not the others? Also svnversion sometimes returns two colon separated values. When it returns two, the second one is correct, but sometimes it just returns one that's wrong. Nov 8, 2019 at 17:00
  • Well, as you can see on my screenshots, these commands do return the highlighted revision number on my machine and repository. There is a subtle difference between revision and last-changed-revision, sometimes they are the same, sometimes they are different. The revision number is the revision at which your file is synced up with the repository. The last-changed-revision is the revision during which the file was actually changed. Nov 8, 2019 at 18:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.