May 25, 2021 SVN
Assuming jerry accidentally changes the array .c resulting in a compilation error, he wants to discard the modification. I n this case, the 'revert' operation will come in play. The revert operation undoes any local changes in the file or directory.
[jerry@CentOS trunk]$ svn status
The above command will have the following effect
M array.c
Let's try to create an array, as follows:
[jerry@CentOS trunk]$ make array
The above command will have the following effect
cc array.c -o array
array.c: In function ‘main’:
array.c:26: error: ‘n’ undeclared (first use in this function)
array.c:26: error: (Each undeclared identifier is reported only once
array.c:26: error: for each function it appears in.)
array.c:34: error: ‘arr’ undeclared (first use in this function)
make: *** [array] Error 1
Jerry performed .c 'revert' operation in the array file.
[jerry@CentOS trunk]$ svn revert array.c
Reverted 'array.c'
[jerry@CentOS trunk]$ svn status
[jerry@CentOS trunk]$
Now let's start compiling the code.
[jerry@CentOS trunk]$ make array
cc array.c -o array
After the revert operation, his file returned to its original state. T he revert operation not only restores a single file to its original state, but also restores the entire directory to its original state. The recovery directory uses the -R command, as follows.
[jerry@CentOS project_repo]$ pwd
/home/jerry/project_repo
[jerry@CentOS project_repo]$ svn revert -R trunk
Now we know how to undo the changes. B ut what if you want to restore an submitted version! T he Version Control System tool does not allow the deletion of the warehouse's historical records. I n order to eliminate an older version, we have to undo all changes in the old version and then submit a new version. This operation is called reverse merge.
Suppose Jerry adds a piece of code for a linear search operation, and after verification, he submits the changes.
[jerry@CentOS trunk]$ svn diff
Index: array.c
===================================================================
--- array.c (revision 21)
+++ array.c (working copy)
@@ -2,6 +2,16 @@
#define MAX 16
+int linear_search(int *arr, int n, int key)
+{
+ int i;
+
+ for (i = 0; i < n; ++i)
+ if (arr[i] == key)
+ return i;
+ return -1;
+}
+
void bubble_sort(int *arr, int n)
{
int i, j, temp, flag = 1;
[jerry@CentOS trunk]$ svn status
? array
M array.c
[jerry@CentOS trunk]$ svn commit -m "Added code for linear search"
Sending trunk/array.c
Transmitting file data .
Committed revision 22.
Jerry was curious about Tom's previous code. S o he checked Subversion's log information.
[jerry@CentOS trunk]$ svn log
The above command will have the following effect
------------------------------------------------------------------------
r5 | tom | 2013-08-24 17:15:28 +0530 (Sat, 24 Aug 2013) | 1 line
Add binary search operation
------------------------------------------------------------------------
r4 | jerry | 2013-08-18 20:43:25 +0530 (Sun, 18 Aug 2013) | 1 line
Add function to accept input and to display array contents
After reviewing the log information, Jerry realized that he had made a serious mistake. B ecause Tom had written a better two-way search than linear search, Jerry found his code redundant and decided to undo previous revisions to the version. First, find the current version of the repository, which is now version 22, and we'll undo the previous version, such as version 21.
[jerry@CentOS trunk]$ svn up
At revision 22.
[jerry@CentOS trunk]$ svn merge -r 22:21 array.c
--- Reverse-merging r22 into 'array.c':
U array.c
[jerry@CentOS trunk]$ svn commit -m "Reverted to revision 21"
Sending trunk/array.c
Transmitting file data .
Committed revision 23.