如何获取已移除的git-svn文件的完整SVN URL?
When working with git-svn on an SVN subdirectory checkout, getting the SVN URL for a deleted file is totally doable with a few git-svn commands—even scriptable ones. Here's how:
Direct Approach (Single File)
First, find any commit where the file still existed. You can use git log --full-history -- path/to/removed_file.py to list commits involving the file, then pick a commit hash where it was present (e.g., the last commit before deletion).
Once you have that commit hash, run:
git svn info --url <COMMIT_HASH>:path/to/removed_file.py
This will spit out the full SVN URL for the file as it existed in that commit. git-svn retains the SVN metadata for files in commits where they were present, so this works even if the file is gone from your current working tree.
Scriptable Method (Automate the Process)
To make this repeatable (great for scripts), you can automate finding the last commit where the file existed and fetching its SVN URL in one go:
#!/bin/bash FILE_PATH="path/to/removed_file.py" # Get the last commit where the file was present LAST_COMMIT=$(git rev-list --full-history --max-count=1 -- "$FILE_PATH") if [ -z "$LAST_COMMIT" ]; then echo "Error: No commit history found for $FILE_PATH" exit 1 fi # Retrieve the SVN URL from that commit git svn info --url "$LAST_COMMIT:$FILE_PATH"
How this works:
git rev-list --full-history --max-count=1 -- $FILE_PATHfinds the most recent commit where the file was part of the repository (even if it was deleted later).- Passing that commit hash with the file path to
git svn info --urlpulls the original SVN URL from the commit's metadata.
Using the URL to Access Older SVN History
Once you have the full SVN URL, you can use the SVN revision number from your git log entries (the suffix in git-svn commit messages like git-svn-id: ...@1234) to query earlier history with:
svn log <FULL_SVN_URL>@<SVN_REVISION>
This lets you trace the file's history back before it was moved into your git-svn subdirectory checkout.
内容的提问来源于stack exchange,提问作者hans_meine

