SVN: Way to determine revision by comparing file or file content

前端 未结 2 1000
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-24 04:35

I have a scenario where I have a file and I need to know what revision in source this file is.

I may have hundreds of revisions on a particular file and have a file that

2条回答
  •  隐瞒了意图╮
    2021-01-24 05:08

    Cribbing a bit off of this answer, here's a quick and dirty batch file that will do the job, assuming the input file is already under version control.

    @echo off
    
    set file=%1
    set temp_file="temp.file"
    
    if [%file%] == [] (
      echo Usage: "%0 "
      exit /b
    )
    
    for /F "tokens=1 delims=-r " %%R in ('"svn log -q %file%"') do (
      svn cat -r %%R %file% > %temp_file%
      fc %temp_file% %file% > nul
      if errorlevel 0 if not errorlevel 1 echo Matches revision r%%R
      del /Q %temp_file%
    )
    

    This gets the log for the filename given, and for each revision does the following:

    • dumps the version of the file at that revision to a temporary file on disk
    • compares the dumped revision with the input file
    • if they're equivalent, fc sets errorlevel to 0, so check for that and output Matches revision r###
    • removes the temporary file

提交回复
热议问题