windows SVN:如何知道文件在哪个修订版中被删除?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6770934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:31:30  来源:igfitidea点击:

SVN: How to know in which revision a file was deleted?

windowssvncommand-line

提问by Viet

Given that I'm using svn command line on Windows, how to find the revision number, in which a file was deleted? On Windows, there are no fancy stuff like grep and I attempting to use command line only, without TortoiseSVN. Thanks in advance!

鉴于我在 Windows 上使用 svn 命令行,如何找到已删除文件的修订号?在 Windows 上,没有像 grep 这样的花哨的东西,我只尝试使用命令行,没有 TortoiseSVN。提前致谢!

EDIT:

编辑:

  • I saw a few posts, like examining history of deleted filebut it did not answer my question.
  • Is there any way other than svn log -v url > log.out and search with Notepad?

回答by Nesze

Install Cygwin.

安装 Cygwin。

I use this:

我用这个:

svn log -v --limit <nr> -v | grep -E '<fileName>|^r' | grep -B 1 <fileName>

where

在哪里

fileName - the name of the file or any pattern which matches it
nr - the number of latest revisions in which I want to look for

This will give you the revisions for all the actions (add, delete, remove, modify) concerning the file, but with a simple tweak with grepyou can get the revisions only for deletion.

这将为您提供有关文件的所有操作(添加、删除、删除、修改)grep的修订,但通过简单的调整,您可以获得仅用于删除的修订。

(Obviously, --limit is optional, however you usually have an overview about how deep you need to search which gains you some performance.)

(显然,--limit 是可选的,但是您通常会大致了解需要搜索多深才能获得一些性能。)

回答by Spudley

The log is the place to look. I know you don't want to hear that answer, but that is where you need to look for deleted files in SVN.

日志是查看的地方。我知道您不想听到那个答案,但这就是您需要在 SVN 中查找已删除文件的地方。

The reason for this is simply that a deleted file is not visible after it's been deleted. The only place to find out about its existence at all is either in the logs, or by fetching out an earlier revision prior to it being deleted.

原因很简单,删除的文件在删除后不可见。找出它存在的唯一地方要么是在日志中,要么是在它被删除之前取出较早的修订版。

The easiest way I know of to deal with this problem is to move away from the the command line, and use a GUI tool such as TortoiseSVN.

我所知道的处理这个问题的最简单方法是远离命令行,并使用诸如TortoiseSVN 之类的 GUI 工具。

TortoiseSVN links itself into the standard Windows file Explorer, so it's very easy to use. In the context of answering this question, you would still use it to look at the logs, but it becomes a much quicker excersise:

TortoiseSVN 将自身链接到标准的 Windows 文件资源管理器,因此非常易于使用。在回答这个问题的上下文中,您仍然会使用它来查看日志,但它会变得更快:

Browser to the SVN folder you want to examine. Then right-click on the folder icon and select TortoiseSVN -> View Logsfrom the context menu.

浏览到要检查的 SVN 文件夹。然后右键单击文件夹图标并从上下文菜单中选择TortoiseSVN -> 查看日志

You'll now get a window showing all the revisions made in that folder. In particular, it is easy to see which revisions have had additions and deletions, because the list includes a set of Action icons for each revision. You can double-click on a revision to get a list of files that were changed (or straight into a diff view if only one file was changed)

您现在将看到一个窗口,显示在该文件夹中所做的所有修订。尤其是,很容易看到哪些修订有增删改查,因为列表中包含了每个修订的一组操作图标。您可以双击修订以获取已更改文件的列表(如果仅更改了一个文件,则可以直接进入差异视图)

So you can easily see which revisions have had deletions, and you can quickly click them to find out which files were involved. It really is that easy.

因此,您可以轻松查看哪些修订已被删除,您可以快速单击它们以找出涉及哪些文件。它真的很容易。

I know you're asking about the command-line, but for administrative tasks like this, a GUI browser really does make sense. It makes it much quicker to see what's happening compared with trying to read through pages of cryptic text (no matter how well versed you are at reading that text).

我知道您问的是命令行,但是对于像这样的管理任务,GUI 浏览器确实很有意义。与尝试通读几页神秘的文本(无论您阅读该文本的能力如何)相比,它可以更快地了解正在发生的事情。

回答by wolfrevo

This question was posted and answered some time ago. In this answer I'll try to show a flexible way to get the informations asked and extend it.

这个问题是前一段时间发布并回答的。在这个答案中,我将尝试展示一种灵活的方式来获取所询问的信息并对其进行扩展。

In cygwin, use svn login combination with awk

在 cygwin 中,svn log结合使用awk

REPO_URL=https://<hostname>/path/to/repo
FILENAME=/path/to/file

svn log ${REPO_URL} -v --search "${FILENAME}" | \
    awk -v var="^   [D] ${FILENAME}$" \
    '/^r[0-9]+/{rev=}; \
    
svn log ${REPO_URL} -v --search "${FILENAME}" | \
    awk -v var="^   [DAMR] ${FILENAME}$" \
    '/^r[0-9]+/ {rev=}; \
    
svn log ${REPO_URL} -v --search "${FILENAME}" | \
    awk -v var="^   [DAMR] ${FILENAME}$" \
    '/^r[0-9]+/ {rev=;user=;date=;time=}; \
    ##代码## ~ var {print rev " | " user " | " date " | " time " | " ##代码##}'
~ var {print rev ##代码##}'
~ var {print rev ##代码##}'
  • svn log ${REPO_URL} -v --search "${FILENAME}"asks svn log for a verbose log containing ${FILENAME}. This reduces the data transfer.
  • The result is piped to awk. awkgets ${FILENAME}passed via -vin the var vartogether with search pattern var="^ [D] ${FILENAME}$"
  • In the awkprogram /^r[0-9]+/ {rev=$1}assigns the revision number to revif line matches /^r[0-9]+/.
  • For every line matching ^ [D] ${FILENAME}$awk prints the stored revision number revand the line: $0 ~ var {print rev $0}
  • svn log ${REPO_URL} -v --search "${FILENAME}"向 svn log 询问包含 ${FILENAME} 的详细日志。这减少了数据传输。
  • 结果通过管道传送到awk. awk${FILENAME}通过传递-v在varvar连同搜索模式var="^ [D] ${FILENAME}$"
  • awk程序/^r[0-9]+/ {rev=$1}中将修订号分配给revif line matching /^r[0-9]+/
  • 对于匹配^ [D] ${FILENAME}$awk 的每一行,打印存储的修订号rev和行:$0 ~ var {print rev $0}

if you're interested not only in the deletion of the file but also creation, modification, replacing, change Din var="^ [D] ${FILENAME}$"to DAMR.

如果你不仅在文件,还可以创建,修改,替换,更改删除感兴趣Dvar="^ [D] ${FILENAME}$"DAMR

The following will give you all the changes:

以下将为您提供所有更改:

##代码##

And if you're interested in username, date and time:

如果您对用户名、日期和时间感兴趣:

##代码##