代码之家  ›  专栏  ›  技术社区  ›  Gordon Wilson

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

svn
  •  158
  • Gordon Wilson  · 技术社区  · 17 年前

    svn diff -r a:b repo 查看两个指定修订之间的更改。我想要的是更改文件的每个版本的差异。有这样的命令吗?

    9 回复  |  直到 17 年前
        1
  •  186
  •   Daniel Gray    9 年前

    它没有内置命令,所以我通常只执行以下操作:

    #!/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
        }
    }
    

    然后,您可以通过以下方式调用它:

    history_of_file $1
    
        2
  •  152
  •   ngn    17 年前

    svn blame filename
    

    它将打印文件,每行前缀为上次更改文件的提交的时间和作者。

        3
  •  99
  •   emilie zawadzki    12 年前

    如果要查看包含代码更改的文件的整个历史记录,请执行以下操作:

    svn log --diff [path_to_file] > log.txt
    
        4
  •  38
  •   Greg Hewgill    17 年前

    git-svn 要将存储库导入Git存储库,请使用 git log -p filename . 这将显示文件的每个日志条目,后跟相应的差异。

        5
  •  21
  •   Jack Jack    17 年前

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

    svn diff .

        6
  •  8
  •   goosemanjack    14 年前

    奇怪的“责备”命令就是这样做的。如果您使用Ortoise,它会给您一个“来自修订版”对话框,然后是一个文件列表,旁边有一行一行的修订号和作者指示符。

    如果右键单击修订信息,可以打开一个“显示日志”对话框,该对话框提供完整的签入信息以及签入过程中的其他文件。

        7
  •  3
  •   D-Rock    17 年前

        8
  •  3
  •   dlink    13 年前

    谢谢你,本丁。我非常喜欢你的解决方案。

    svnhistory elements.py |more
    

    #!/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
    
        9
  •  1
  •   alamba    7 年前

    在研究这个话题的时候,我已经看到了很多部分答案。这对我来说很有用,希望它能帮助别人。此命令将在命令行上显示输出,显示修订号、作者、修订时间戳和所做的更改:

    svn blame -v <filename>