如何只检出在一系列 SVN 修订版中修改过的文件?

发布于 2024-07-10 12:03:56 字数 57 浏览 11 评论 0原文

是否可以仅从 SVN 存储库中签出在一个修订版或修订版范围内修改过的文件,而不签出任何未修改的文件?

Is it possible to checkout only those files from a SVN repository that were modified in a revision or range of revisions, without checking out any files that were not modified?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

煮酒 2024-07-17 12:03:56

我的建议与弗洛洛的建议相同。 但是,需要一个范围。
您可以使用以下 shell 函数。

function checkout_files_in_revrange()
{
  svn_url=$1;
  start_rev=$2;
  end_rev=$3;
  for theCheckoutCanditate in `svn log -r $start_rev:$end_rev --verbose --incremental | grep "   M " | cut -f5 -d' ' | cut -f3- -d/`
  do
     svn co $svn_url/$theCheckoutCandidate -q;
  done
}

My suggestion is in the same lines as flolo suggests. But, takes a range.
You could the following shell function.

function checkout_files_in_revrange()
{
  svn_url=$1;
  start_rev=$2;
  end_rev=$3;
  for theCheckoutCanditate in `svn log -r $start_rev:$end_rev --verbose --incremental | grep "   M " | cut -f5 -d' ' | cut -f3- -d/`
  do
     svn co $svn_url/$theCheckoutCandidate -q;
  done
}
蓝天 2024-07-17 12:03:56

据我所知,现在有直接的方法来获取更改的文件而不是全部。

我的想法是:使用列表的详细输出(显示最后更改的版本),通过 awk 过滤它,然后检查其余部分。 例如,要搜索版本 42 中更改的文件,我将使用此

VERSION=42
svn list -v -R -r $VERSION svn://... |  awk "/^[ ]*$VERSION/ {print \$7}" > files_to_checkout

命令,然后执行 svn update -r $VERSION 'cat files_to_checkout'(或 url 上的 co,具体取决于您将在何处运行命令)。

编辑:另外更短:
使用 svn diff 命令,并用 -x 和 --diff-cmd 将 diff 命令替换为 svn co。 这需要一些参数转移黑客(我不会在这里详细说明),但只需要一行并且不需要中间文件(您也可以在上面保存,但这会增加可读性)

There is afaik now direct way to get just the changed files and not all.

My idea would be: use the verbose output of the list (which shows the last changed version), filter it through awk, and checkout the rest. E.g. to search the files which changed in version 42 I would use this

VERSION=42
svn list -v -R -r $VERSION svn://... |  awk "/^[ ]*$VERSION/ {print \$7}" > files_to_checkout

And later do a svn update -r $VERSION 'cat files_to_checkout'(or a co on the url, depending on where you will run the command).

EDIT: Additional even shorter:
use the svn diff command, and replace with -x and --diff-cmd the diff command with svn co. This requires some argument shifting hacking (which I wont elaborate here), but needs just one line and no intermedate file (which you could save above too, but that would have cost readability)

稀香 2024-07-17 12:03:56

如果您将 svn log 与 -v (详细选项)一起使用:

svn log -r <revision> -v <path>

您将获得包含更改的文件的输出:

 r3 | ciaran | 2008-11-16 12:24:30 +0000 (Sun, 16 Nov 2008) | 1 line
Changed paths:
   A /trunk/apache/apache.conf
   A /trunk/application/controllers

Commit message goes here

您应该能够通过一些 grep 等操作它来生成一系列 svn co 命令。

If you use svn log with the -v (verbose option):

svn log -r <revision> -v <path>

You will get an output that includes the changed files:

 r3 | ciaran | 2008-11-16 12:24:30 +0000 (Sun, 16 Nov 2008) | 1 line
Changed paths:
   A /trunk/apache/apache.conf
   A /trunk/application/controllers

Commit message goes here

You should be able to manipulate that with some grepping etc. to produce a sequence of svn co commands.

王权女流氓 2024-07-17 12:03:56

我们在 MSBuild 脚本中执行此操作:

步骤 1: - 使用 diff 命令获取修改文件的列表,将输出重定向到目标目录中的临时文件
步骤 2: - 将临时文件读入 itemGroup

<Exec command="$(svnExecutable) diff -r $(StartRevision):$(EndRevision) $(DOUBLE_QUOTES)$(SvnRepositoryPath)/$(DOUBLE_QUOTES) --no-diff-deleted --summarize > $(TempFilePath)" WorkingDirectory="$(WorkDirectory)" />

We do this in an MSBuild script:

Step 1: - Use the diff command to get the list of modified files, redirect output into a temporary file in the target directory
Step 2: - Read the temporary file into an itemGroup

<Exec command="$(svnExecutable) diff -r $(StartRevision):$(EndRevision) $(DOUBLE_QUOTES)$(SvnRepositoryPath)/$(DOUBLE_QUOTES) --no-diff-deleted --summarize > $(TempFilePath)" WorkingDirectory="$(WorkDirectory)" />

千寻… 2024-07-17 12:03:56

我不完全确定这是否可能,但您也可以执行以下操作:

svn checkout --revision <revisionNumber> 

获取某个修订版并

svn log --revision <revisionNumber> 

列出修订版中更改的所有文件

I'm not completly sure if this is possible but you can also do something like this:

svn checkout --revision <revisionNumber> 

to get a certain revision and

svn log --revision <revisionNumber> 

to list all files chaned in a revision

两仪 2024-07-17 12:03:56

在与大多数人建议的几乎相同的行中(但是仅在具有 grep 和 awk 的系统中),您可以通过执行

svn log -v --revision来获取列表。 | grep“^”| awk '{print $2}'.

In almost the same lines as most of the folks have suggested, (however only in a system with grep and awk), you can get the list by executing

svn log -v --revision <revision_number> | grep "^ " | awk '{print $2}'.

ㄖ落Θ余辉 2024-07-17 12:03:56

回答你的问题的另一种方法:

假设你有一个现有的工作副本,你应该只在包含你正在查看的文件的目录的根目录上使用“svn update”,因为它可以准确地检索当前版本和 HEAD 版本之间的更改尽可能少的数据。

较旧的源代码管理系统(例如 CVS 和 VSS)会向服务器询问每个文件此文件是否已更改?,而 subversion 只是将树的更改作为单个操作发送。 当您将文件列表传递给 svn update 时,您就没有这个优势。

因此,传输已更改内容的最有效方法就是更新。 与工作副本的基本版本相比,这仅传输 HEAD 中更改的二进制差异。


如果您试图解决的问题是 svn update 速度太慢,那么我们正在尝试为 Subversion 1.7 解决这个问题。

此版本将引入一种新的工作副本数据存储格式,该格式将使必须锁定整个工作副本(例如更新)的简单操作变得更快。

Another take at answering your question:

Assuming you have an existing workingcopy you should just use 'svn update' on the root of the directory containing the files you are looking at as that retrieves exactly what changed between your current revision and the HEAD revision with the least data possible.

Older sourcecode management systems like CVS and VSS asked the server for every file has this file changed?, while subversion just sends the changes of a tree as a single action. When you pass a list of files to svn update you don't have this advantage.

Therefore the most efficient way to transfer what has changed is just updating. This only transfers a binary diff of the changes in HEAD compared to the base version of your working copy.


If the problem you are trying to solve is that svn update is to slow, then we are trying to solve that for Subversion 1.7.

This version will introduce a new working copy data storage format that will make simple operations that have to lock an entire working copy (like updating) much faster.

晨曦÷微暖 2024-07-17 12:03:56

svn diff -rstarting_revision:ending_revision_or_HEAD --summarize

svn diff -r starting_revision:ending_revision_or_HEAD --summarize

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文