When you delete a file within a batch script and recreate it with a Java program, SVN treats it as a new, unversioned file. Therefore, when you access the log of the file, you only see the history from the point it was recreated, not from its original creation.
However, the parent folder’s log keeps track of all changes, including the deletion and recreation of files within it. That’s why you can still see the file’s original history in the parent folder’s log. Is this expected behaviour?
I am using svn 1.14
Yes, this is expected behavior if a file is deleted in Subversion and added again, it's considered replaced. It will lose all history (it's a new file, after all) but the containing folder will still know about the older file with the same name. It will be marked as R
, for replaced.
On the other hand, if a file is only deleted from the file system and restored without notifying Subversion (i.e. without calls to svn rm
and svn add
or the respective TortoiseSVN actions) it will look modified to Subversion.
It will be marked with an M
. There's no indication it was ever missing. It's as if somebody changed the file. Its history will be continuous.
Quoting from the Red Bean Book, chapter about status:
'M'
Item has been modified.
'R'
Item has been replaced in your working copy. This means the file was scheduled for deletion, and then a new file with the same name was scheduled for addition in its place.
I wrote a simple batch file that illustrates both cases side by side. It assumes two files replace.txt
and modify.txt
that were created empty and committed.
svn rm replace.txt
echo "this line emulates the Java program" > replace.txt
svn add replace.txt
del modify.txt
echo "this line emulates the Java program" > modify.txt
svn commit -m"Update by batch file"
Note how replace.txt
undergoes svn rm
and svn add
while modify.txt
is just deleted. In the end, both files are svn commit
ted.
And this is how it will show up (after an svn update
) in svn log -l2 -v
:
------------------------------------------------------------------------
r13 | me | 2024-02-02 20:59:09 +0100 (Fri, 02 Feb 2024) | 1 line
Changed paths:
M /foo/modify.txt
R /foo/replace.txt
Update by batch file
------------------------------------------------------------------------
r12 | me | 2024-02-02 20:59:03 +0100 (Fri, 02 Feb 2024) | 1 line
Changed paths:
A /foo/modify.txt
A /foo/replace.txt
Create two files for demo
------------------------------------------------------------------------
Note the R
and M
markers.
I won't repeat the logs for the individual files but replace.txt
will only have the entry for r13 while modify.txt
's log looks like the one above.
Bottom line, there's a difference between svn rm
'ing files and deleting files. When replacing files, they will lose all history. Use this when you intend to do it. For most uses, just modifying the file is what you want.