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

前端 未结 3 1316
死守一世寂寞
死守一世寂寞 2021-02-03 23:54

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

3条回答
  •  名媛妹妹
    2021-02-04 00:30

    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 log in combination with awk

    REPO_URL=https:///path/to/repo
    FILENAME=/path/to/file
    
    svn log ${REPO_URL} -v --search "${FILENAME}" | \
        awk -v var="^   [D] ${FILENAME}$" \
        '/^r[0-9]+/{rev=$1}; \
        $0 ~ var {print rev $0}'
    
    • 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. awk gets ${FILENAME} passed via -v in the var vartogether with search pattern var="^ [D] ${FILENAME}$"
    • In the awk program /^r[0-9]+/ {rev=$1} assigns the revision number to rev if line matches /^r[0-9]+/.
    • For every line matching ^ [D] ${FILENAME}$ awk prints the stored revision number rev and the line: $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.

    The following will give you all the changes:

    svn log ${REPO_URL} -v --search "${FILENAME}" | \
        awk -v var="^   [DAMR] ${FILENAME}$" \
        '/^r[0-9]+/ {rev=$1}; \
        $0 ~ var {print rev $0}'
    

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

    svn log ${REPO_URL} -v --search "${FILENAME}" | \
        awk -v var="^   [DAMR] ${FILENAME}$" \
        '/^r[0-9]+/ {rev=$1;user=$3;date=$5;time=$6}; \
        $0 ~ var {print rev " | " user " | " date " | " time " | " $0}'
    

提交回复
热议问题