examining history of deleted file

前端 未结 17 1738
臣服心动
臣服心动 2020-11-30 17:36

If I delete a file in Subversion, how can I look at it\'s history and contents? If I try to do svn cat or svn log on a nonexistent file, it complai

相关标签:
17条回答
  • 2020-11-30 18:09

    It's nothing particularly special in git. If you know the name of the file, you can find out the change that removed it with log:

    git log -n 1 -- filename
    

    Then you can use that commit to get the file as it existed before the deletion.

    git checkout [last_revision]^ filename
    

    Example:

    dhcp-120:/tmp/slosh 587% ls -l slosh.tac
    ls: slosh.tac: No such file or directory
    dhcp-120:/tmp/slosh 588% git log -n 1 -- slosh.tac
    commit 8d4a1f1a94e4aa37c1cb9d329a140d08eec1b587
    Author: Dustin Sallings <dustin@spy.net>
    Date:   Mon Dec 15 11:25:00 2008 -0800
    
        Get rid of a .conf and replace it with .tac.
    dhcp-120:/tmp/slosh 589% git checkout 8d4a1f^ slosh.tac
    dhcp-120:/tmp/slosh 590% ll slosh.tac
    -rw-------  1 dustin  wheel  822 Dec 30 12:52 slosh.tac
    

    Note that this does not actually put the file back in revision control. It simply drops the file as it existed in its final state into the current location. You can then add it or just inspect it or whatever from that point.

    0 讨论(0)
  • 2020-11-30 18:12

    If you don't know the path to the deleted file, turns out you can search for it in the otherwise all-too-heavy svn log command:

    svn log --search <deleted_file_or_pattern> -v
    

    The command is probably hammering the server just as much as it would without the search option, but at least the rest of involved resources (including your eyeballs) would be kinda relieved, since that will tell you in which revision that file was deleted. Then, you can follow the other tips (mainly using the same svn log command, but already on a defined path).

    0 讨论(0)
  • 2020-11-30 18:15
    svn log -v | grep -B50 YourDeletedFileName
    

    Will get you the path and revision. In git (also checks for renames):

    git log --diff-filter=DR --name-only | grep -B50 YourDeletedFileName
    
    0 讨论(0)
  • 2020-11-30 18:17

    A solution using only the GUI:

    If you know the name of the file, but don't know its last revision number or even its path:

    1. From Repo Browser do a "Show log" on the root
    2. Hit "Show All" (at the bottom of the log dialog)
    3. Type the filename into the Filter textbox (at the top of the log dialog)

    This will then show only those revisions where the file was added/modified/deleted. This is your history of the file.

    Note that if the file was deleted by deleting one of its parent folders, it won't have a 'deleted' entry in the log (and so mjy's solution won't work). In this case, its most recent entry in the filtered log will correspond to its contents at deletion.

    0 讨论(0)
  • 2020-11-30 18:18

    Use this command:

    svn log -v | awk '/^r[0-9]+/ { rev = $1; }; / D .*filename_escaped_for_regex/ { print rev" "$2; };'
    

    This will list all revisions that ever deleted any files matching the pattern. That is, if you're searching for file README, then all of /src/README, /src/README.first, and /some/deeply/hidden/directory/READMENOT will be found and listed.

    If your filename contains slashes (path), dots, or other special regex characters, don't forget to escape them to avoid mismatching or errors.

    0 讨论(0)
  • 2020-11-30 18:18

    You would need to specify a revision.

    svn log -r <revision> <deleted file>
    
    0 讨论(0)
提交回复
热议问题