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

旧巷老猫 提交于 2019-12-20 04:50:33

问题


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 matches one or more of those revisions. Is there any way in Tortoise, Cornerstone or through the command line to do this?

Apologies if the question isn't the clearest. To be honest I'm not sure how to phrase what I'm looking for.

I found a similar question about git here;

GIT: determine revision based on a file


回答1:


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 <file>"
  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



回答2:


If you have to use any content outside VCS and identify corresponding resisions and don't add this data to file (text file) or repository (binaries) - it's your fail (Git-boys must suffer and be excruciated, because they haven't keywords directly /but have smudge|clean filters/ and revision properties /?/, but in SVN you have these possibilities). Re-think about your workflow and start using Power!

In your current state (no keywords, no metadata) you can (for each file)

  • calculate any available hash for unversioned file
  • calculate the same hash for this file for all revisions in question in repo
  • compare hashes and find a match(es)


来源:https://stackoverflow.com/questions/39222814/svn-way-to-determine-revision-by-comparing-file-or-file-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!