简体   繁体   English

如何查看SVN中文件的所有历史更改

[英]How can I view all historical changes to a file in SVN

I know that I can svn diff -ra:b repo to view the changes between the two specified revisions. 我知道我可以svn diff -ra:b repo查看两个指定修订版本之间的更改。 What I'd like is a diff for every revision that changed the file. 我想要的是每个修改文件的差异。 Is such a command available? 这样的命令可用吗?

There's no built-in command for it, so I usually just do something like this: 它没有内置命令,所以我通常只做这样的事情:

#!/bin/bash

# history_of_file
#
# Outputs the full history of a given file as a sequence of
# logentry/diff pairs.  The first revision of the file is emitted as
# full text since there's not previous version to compare it to.

function history_of_file() {
    url=$1 # current url of file
    svn log -q $url | grep -E -e "^r[[:digit:]]+" -o | cut -c2- | sort -n | {

#       first revision as full text
        echo
        read r
        svn log -r$r $url@HEAD
        svn cat -r$r $url@HEAD
        echo

#       remaining revisions as differences to previous revision
        while read r
        do
            echo
            svn log -r$r $url@HEAD
            svn diff -c$r $url@HEAD
            echo
        done
    }
}

Then, you can call it with: 然后,你可以用:

history_of_file $1

Slightly different from what you described, but I think this might be what you actually need: 与您描述的略有不同,但我认为这可能是您实际需要的:

svn blame filename

It will print the file with each line prefixed by the time and author of the commit that last changed it. 它将打印文件,每行以前一次更改它的提交的时间和作者为前缀。

如果要查看包含代码更改的文件的完整历史记录:

svn log --diff [path_to_file] > log.txt

You could use git-svn to import the repository into a Git repository, then use git log -p filename . 您可以使用git-svn将存储库导入Git存储库,然后使用git log -p filename This shows each log entry for the file followed by the corresponding diff. 这显示了文件的每个日志条目,后跟相应的diff。

Start with 从...开始

svn log -q file | grep '^r' | cut -f1 -d' '

That will get you a list of revisions where the file changed, which you can then use to script repeated calls to svn diff . 这将为您提供文件更改的修订列表,然后您可以使用该列表重复调用svn diff

The oddly named "blame" command does this. 奇怪命名的“责备”命令就是这样做的。 If you use Tortoise, it gives you a "from revision" dialog, then a file listing with a line by line indicator of Revision number and author next to it. 如果你使用Tortoise,它会给你一个“from revision”对话框,然后是一个文件列表,其中包含一行一行的修订版号和作者旁边的作者。

If you right click on the revision info, you can bring up a "Show log" dialog that gives full checkin information, along with other files that were part of the checkin. 如果右键单击修订信息,则可以打开一个“显示日志”对话框,其中提供完整的签入信息以及签入的其他文件。

Thanks, Bendin. 谢谢,本丁。 I like your solution very much. 我非常喜欢你的解决方案。

I changed it to work in reverse order, showing most recent changes first. 我将其更改为按相反顺序工作,首先显示最近的更改。 Which is important with long standing code, maintained over several years. 对于长期存在的代码而言,这一点非常重要,可持续数年。 I usually pipe it into more. 我通常把它管成更多。

svnhistory elements.py |more

I added -r to the sort. 我添加-r到排序。 I removed spec. 我删除了规范。 handling for 'first record'. 处理'第一记录'。 It is it will error out on the last entry, as there is nothing to diff it with. 它会在最后一个条目中出错,因为没有什么可以区分它。 Though I am living with it because I never get down that far. 虽然我和它一起生活,因为我从来没有这么做过。

#!/bin/bash                                                                    

# history_of_file                                                              
#                                                                              
# Bendin on Stack Overflow: http://stackoverflow.com/questions/282802          
#   Outputs the full history of a given file as a sequence of                  
#   logentry/diff pairs.  The first revision of the file is emitted as         
#   full text since there's not previous version to compare it to.             
#                                                                              
# Dlink                                                                        
#   Made to work in reverse order                                              

function history_of_file() {
    url=$1 # current url of file                                               
    svn log -q $url | grep -E -e "^r[[:digit:]]+" -o | cut -c2- | sort -nr | {
        while read r
    do
            echo
            svn log -r$r $url@HEAD
            svn diff -c$r $url@HEAD
            echo
    done
    }
}

history_of_file $1

As far as I know there is no built in svn command to accomplish this. 据我所知,没有内置的svn命令来实现这一目标。 You would need to write a script to run several commands to build all the diffs. 您需要编写一个脚本来运行几个命令来构建所有差异。 A simpler approach would be to use a GUI svn client if that is an option. 一个更简单的方法是使用GUI svn客户端,如果这是一个选项。 Many of them such as the subversive plugin for Eclipse will list the history of a file as well as allow you to view the diff of each revision. 其中许多例如Eclipse的颠覆性插件将列出文件的历史记录,并允许您查看每个修订版的差异。

I've seen a bunch of partial answers while researching this topic. 在研究这个主题时,我已经看到了一些部分答案。 This is what worked for me and hope it helps others. 这对我有用,希望能帮到别人。 This command will display output on the command line, showing the revision number, author, revision timestamp and changes made: 此命令将在命令行上显示输出,显示修订号,作者,修订时间戳和所做的更改:

svn blame -v <filename>

To make your search easier, you can write the output to a file and grep for what you're looking for. 为了使您的搜索更容易,您可以将输出写入文件并grep查找您要查找的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM