Reputation: 53358
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
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?
Upvotes: 2
Views: 2822
Reputation: 53358
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
Upvotes: 3
Reputation: 340516
Use the COMMITTED
alias instead of HEAD
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)
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 --
------------------------------------------------------------------------
Upvotes: 2
Reputation: 189
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 }'
Upvotes: 0