As we mentioned earlier, the repository is like a time machine. It keeps a record of every change ever committed, and allows you to explore this history by examining previous versions of files and directories as well as the metadata that accompanies them. With a single Subversion command, you can check out the repository (or restore an existing working copy) exactly as it was at any date or revision number in the past. However, sometimes you just want to peer into the past instead of going into the past.
Come si è detto, il repository è come una macchina del tempo. Mantiene una registrazione di tutte le modifiche di cui si è fatto la commit, e permette di esplorare la storia esaminando precedenti versioni di file e directory così come i metadati che li accompagnano. Con un singolo comando Subversion, si può fare il check out del repository (oppure ripristinare una una copia di lavoro esistente) esattamente come se fosse ad una data o a un numero di revisione nel passato. Comunque, a volte si vuole solo essere al passo con il passato invece di andare nel passato.
There are several commands that can provide you with historical data from the repository:
Ci sono diversi comandi che provvedono alle date nel repository:
Shows you broad information: log messages with date and author information attached to revisions, and which paths changed in each revision.
Mostra informazioni generali: vengono allegati alle revisioni messaggi di log con data e informazioni sull'autore, e quali percorsi sono stati cambiati in ogni revisione.
Shows you the specific details of how a file changed over time.
Mostra i dettagli di come un file è cambiato nel tempo.
This is used to retrieve any file as it existed in a particular revision number and display it on your screen.
È usato per caricare qualsiasi file così com'era in un particolare numero di revisione e visualizzarlo.
Displays the files in a directory for any given revision.
Visualizza i file in una directory per ogni data revisione.
To find information about the history of a file or directory, use the svn log command. svn log will provide you with a record of who made changes to a file or directory, at what revision it changed, the time and date of that revision, and, if it was provided, the log message that accompanied the commit.
Per trovare informazioni sulla storia di un file o una directory, si usa il comando svn log. svn log fornirà una registrazione di chi ha fatto modifiche ad un file o una directory, a quale revisione è stato modificato, l'ora e il giorno della revisione, e, se previsto, il messaggio di log che ha accompagnato la commit.
$ svn log ------------------------------------------------------------------------ r3 | sally | Mon, 15 Jul 2002 18:03:46 -0500 | 1 line Added include lines and corrected # of cheese slices. ------------------------------------------------------------------------ r2 | harry | Mon, 15 Jul 2002 17:47:57 -0500 | 1 line Added main() methods. ------------------------------------------------------------------------ r1 | sally | Mon, 15 Jul 2002 17:40:08 -0500 | 1 line Initial import ------------------------------------------------------------------------
Note that the log messages are printed in
reverse chronological order by default.
If you wish to see a different range of revisions in a
particular order, or just a single revision, pass the
--revision
(-r
)
switch:
Si noti che i messaggi di log sono stampati predefinitamente in
ordine cronologico inverso. Se si desidera vedere
un differente intrevallo di revisioni in un ordine particolare, o solo
una singola revisione, bisogna usare l'opzione
--revision
(-r
):
$ svn log --revision 5:19 # shows logs 5 through 19 in chronological order $ svn log -r 19:5 # shows logs 5 through 19 in reverse order $ svn log -r 8 # shows log for revision 8
You can also examine the log history of a single file or directory. For example:
Si può esaminare la storia dei log di un singolo file o directory. Ad esempio:
$ svn log foo.c … $ svn log http://foo.com/svn/trunk/code/foo.c …
These will display log messages only for those revisions in which the working file (or URL) changed.
Sarà mostrato solo il log di quelle revisioni in cui il file di lavoro (o URL) è cambiato.
If you want even more information about a file or
directory, svn log also takes a
--verbose
(-v
) switch.
Because Subversion allows you to move and copy files and
directories, it is important to be able to track path changes
in the filesystem, so in verbose mode, svn
log will include a list of changed paths in a
revision in its output:
Se si vogliono maggiori informazioni su un file o una directory,
svn log possiede anche l'opzione
--verbose
(-v
). Poiché Subversion
permette di spostare e copiare file e directory, è importante
riuscire a tener traccia dei cambiamenti di percorso nel filesystem,
così in modalità verbose, svn log nel suo output
includerà una lista dei percorsi modificati in una revisione :
$ svn log -r 8 -v ------------------------------------------------------------------------ r8 | sally | 2002-07-14 08:15:29 -0500 | 1 line Changed paths: M /trunk/code/foo.c M /trunk/code/bar.h A /trunk/code/doc/README Frozzled the sub-space winch. ------------------------------------------------------------------------
svn log also takes a --quiet
(-q
) switch, which suppresses the body of the
log message. When combined with --verbose
, it
gives just the names of the changed files.
svn log possiede anche un'opzione
--quiet
(-q
), che sopprime il corpo
del messaggio di log. Quando è combinata con l'opzione
--verbose
, essa fornisce solo i nomi dei files
modificati.
We've already seen svn diff before—it displays file differences in unified diff format; it was used to show the local modifications made to our working copy before committing to the repository.
Si è gia visto svn diff precedentemente — mostra le modifiche di un file in un formato unificato diff; è stato usato per mostrare le modifiche locali fatte nella propria copia di lavoro prima di fare la commit al repository.
In fact, it turns out that there are three distinct uses of svn diff:
Infatti, si vede che ci sono tre usi distinti del comandosvn diff:
Examine local changes
Esaminare le modifiche locali
Compare your working copy to the repository
Confrontare la propria copia di lavoro con il repository
Compare repository to repository
Confrontare repository con repository
As we've seen, invoking svn diff with
no switches will compare your working files to the cached
“pristine” copies in
the .svn
area:
Come si è visto, invocando il comando svn diff
senza nessuna opzione compariranno i file di lavoro nella copia
«di ripristino» presente nell'area
.svn
:
$ svn diff Index: rules.txt =================================================================== --- rules.txt (revision 3) +++ rules.txt (working copy) @@ -1,4 +1,5 @@ Be kind to others Freedom = Responsibility Everything in moderation -Chew with your mouth open +Chew with your mouth closed +Listen when others are speaking $
If a single --revision
(-r
) number is passed, then your
working copy is compared to the specified revision in the
repository.
Se si fornisce un solo numero con
l'opzione--revision
(-r
), allora la
propria copia di lavoro è confrontata con una specifica revisione nel
repository.
$ svn diff --revision 3 rules.txt Index: rules.txt =================================================================== --- rules.txt (revision 3) +++ rules.txt (working copy) @@ -1,4 +1,5 @@ Be kind to others Freedom = Responsibility Everything in moderation -Chew with your mouth open +Chew with your mouth closed +Listen when others are speaking $
If two revision numbers, separated by a colon, are
passed via --revision
(-r
), then the two revisions are directly
compared.
Se vengono forniti due numeri di revisione, separati da una
colonna, con l'opzione --revision
(-r
), allora vengono confrontate direttamente le due
revisioni.
$ svn diff --revision 2:3 rules.txt Index: rules.txt =================================================================== --- rules.txt (revision 2) +++ rules.txt (revision 3) @@ -1,4 +1,4 @@ Be kind to others -Freedom = Chocolate Ice Cream +Freedom = Responsibility Everything in moderation Chew with your mouth open $
Not only can you use svn diff to compare files in your working copy to the repository, but if you supply a URL argument, you can examine the differences between items in the repository without even having a working copy. This is especially useful if you wish to inspect changes in a file when you don't have a working copy on your local machine:
Per confrontare i file nella propria copia di lavoro con il repository non solo si può usare il comando svn diff, ma se si fornisce come argomento un URL, si possono esaminare le differenze tra oggetti nel repository anche senza avere una copia di lavoro. Questo è molto utile se si desidera ispezionare le modifiche in un file quando non si ha una copia di lavoro sulla propria macchina:
$ svn diff --revision 4:5 http://svn.red-bean.com/repos/example/trunk/text/rules.txt … $
If you want to examine an earlier version of a file and not necessarily the differences between two files, you can use svn cat:
Se si vuole esaminare una versione precedente di un file e non necessariamente le differenze tra due file, si può usare il comando svn cat:
$ svn cat --revision 2 rules.txt Be kind to others Freedom = Chocolate Ice Cream Everything in moderation Chew with your mouth open $
You can also redirect the output directly into a file:
Si può redirezionare l'output direttamente in un file:
$ svn cat --revision 2 rules.txt > rules.txt.v2 $
You're probably wondering why we don't just use svn update --revision to update the file to the older revision. There are a few reasons why we might prefer to use svn cat.
Probabilmente ci si meraviglierà del fatto che non si usa solo il comando svn update --revision per aggiornare il file ad una versione precedente. Ci sono diverse ragioni per preferire il comando svn cat.
First, you may want to see the differences between two revisions of a file using an external diff program (perhaps a graphical one, or perhaps your file is in such a format that the output of unified diff is nonsensical). In this case, you'll need to grab a copy of the old revision, redirect it to a file, and pass both that and the file in your working copy to your external diff program.
Come prima cosa, si possono voler vedere le differenze tra due revisioni di un file usando un programma diff esterno (magari uno grafico, o magari il file è in un formato tale che l'output in formato unificato diff non avrebbe senso). In questo caso, bisogna prendere una copia della revisione precedente, redirezionarla su un file, e passare sia quella sia il file nella propria copia di lavoro al programma diff esterno.
Sometimes it's easier to look at an older version of a file in its entirety as opposed to just the differences between it and another revision.
A volte è più facile guardare una versione precedente di un file per intero che analizzare solo le differenze tra quella ed un'altra revisione.
The svn list command shows you what files are in a repository directory without actually downloading the files to your local machine:
Il comando svn list mostra quali file sono nel repository senza attualmente scaricarli nalla propria macchina:
$ svn list http://svn.collab.net/repos/svn README branches/ clients/ tags/ trunk/
If you want a more detailed listing, pass the
--verbose
(-v
) flag to get
output like this:
Se si vuole una lista più dettagliata, si deve usrae l'opzione
--verbose
(-v
) per avere un output
come questo:
$ svn list --verbose http://svn.collab.net/repos/svn 2755 harry 1331 Jul 28 02:07 README 2773 sally Jul 29 15:07 branches/ 2769 sally Jul 29 12:07 clients/ 2698 harry Jul 24 18:07 tags/ 2785 sally Jul 29 19:07 trunk/
The columns tell you the revision at which the file or directory was last modified, the user who modified it, the size if it is a file, the date it was last modified, and the item's name.
Le colonne indicano la revisione nella quale il file o la directory è stato modificato l'ultima volta, l'utente che ha eseguito le modifiche, la dimensione se si tratta di un file, la data dell'ultima modifica, e il nome dell'oggetto.
In addition to all of the above commands, you can use
svn update and svn
checkout with the --revision
switch
to take an entire working copy “back in time”
[13]:
In aggiunta a tutti i comandi visti sopra, si possono usare i
comandi svn update e svn checkout
con l'opzione --revision
per portare un'intera copia di
lavoro «indietro nel tempo» [14]:
$ svn checkout --revision 1729 # Checks out a new working copy at r1729 … $ svn update --revision 1729 # Updates an existing working copy to r1729 …