检查已删除文件的历史记录
如果我在 Subversion 中删除文件,如何查看它的历史记录和内容? 如果我尝试对不存在的文件执行 svn cat 或 svn log ,它会抱怨该文件不存在。
另外,如果我想恢复该文件,我应该 svn add
将其恢复吗?
(我特别询问了 Subversion,但我也想听听 Bazaar、Mercurial 和 Git 如何处理这种情况。)
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 complains that the file doesn't exist.
Also, if I wanted to resurrect the file, should I just svn add
it back?
(I asked specifically about Subversion, but I'd also like to hear about how Bazaar, Mercurial, and Git handle this case, too.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(17)
仅使用 GUI 的解决方案:
如果您知道文件名,但不知道其最后版本号,甚至不知道其路径:
这样将仅显示添加/修改/删除文件的修订版本。 这是您的文件历史记录。
请注意,如果通过删除其父文件夹之一来删除文件,则日志中不会有“已删除”条目(因此 mjy 的解决方案将不会出现“工作)。 在这种情况下,过滤日志中的最新条目将与其删除时的内容相对应。
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:
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.
将为您提供路径和修订版本。 在 git 中(还检查重命名):
Will get you the path and revision. In git (also checks for renames):
如果您不知道已删除文件的路径,则可以在过于繁重的
svn log
命令中搜索:该命令可能是就像没有搜索选项一样对服务器进行重击,但至少涉及的其余资源(包括您的眼球)会有所缓解,因为这会告诉您该文件在哪个版本中被删除。 然后,您可以按照其他提示进行操作(主要使用相同的 svn log 命令,但已经在定义的路径上)。
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: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).除了达斯汀的回答之外,如果您只想检查内容,而不是检查它,在他的示例中您可以这样做:
: 分隔修订版和该修订版中的路径,有效地要求特定修订版的特定路径。
In addition to Dustin's answer, if you just want to examine the contents, and not check it out, in his example you can do:
the : separates a revision and a path in that revision, effectively asking for a specific path at a specific revision.
使用此命令:
这将列出曾经删除与该模式匹配的任何文件的所有修订。
也就是说,如果您要搜索文件 README,则搜索所有
/src/README
、/src/README.first
和/some/deeply/将找到并列出隐藏/目录/READMENOT
。如果您的文件名包含斜线(路径)、点或其他特殊正则表达式字符,请不要忘记对它们进行转义以避免不匹配或错误。
Use this command:
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.
发帖者在这里实际上问了3个问题:
我在这里看到的所有答案都是针对问题2和3的。
问题1的答案是:
您仍然需要获取文件上次存在时的修订号,其他人在这里已经明确回答了这一点。
The poster has actually asked 3 questions here:
All the answers I see here are for questions 2 and 3.
The answer to question 1 is:
You still need to get the revision number for when the file last existed, which is clearly answered by others here.
啊,自从我学习使用Bazaar以来,这是我尝试过的。 如果不成功,您似乎无法日志和注释当前已删除的文件...:-(
尝试过:
但奇怪的是(幸运的是)我可以这样做:
并且:
按照上面的错误中的建议:(
调整
-B
(--before-context
) 参数(根据需要)。Ah, since I am learning to use Bazaar, it is something I tried. Without success, it appears you cannot log and annotate removed files currently... :-(
Tried:
but curiously (and fortunately) I can do:
and:
and as suggested in the bug above:
(adjust
-B
(--before-context
) parameter as needed).假设您的文件被命名为 ~/src/a/b/c/deleted.file
示例输出,在 r90440 找到它,
将其复制回以前的版本(90439=90440-1)
Assume your file was named as ~/src/a/b/c/deleted.file
sample output, found it at r90440
copy it back to previous version(90439=90440-1)
您需要指定修订版本。
You would need to specify a revision.
如果您想在重命名文件之前查看文件的历史记录,请按照 这里有一条评论,您可以使用
If you're wanting to look at the history of a file prior to it being renamed, then as mentioned in a comment here you can use
我自己想要一个答案。 尝试以下操作以仅输出
svn log
中的删除内容。这通过awk过滤日志输出。 awk 缓冲它找到的每个修订行,仅在找到删除记录时输出它。 每个修订仅输出一次,因此修订中的多个删除被分组在一起(如标准 svn log 输出)。
您可以指定
--limit
来减少返回的记录数量。 您还可以根据需要删除--stop-on-copy
。我知道有人抱怨解析整个日志的效率。 我认为这是比 grep 及其“广撒网”
-B
选项更好的解决方案。 我不知道它是否更有效,但我想不出 svn log 的替代方案。 它与@Alexander Amelkin 的答案类似,但不需要特定的名称。 这也是我的第一个 awk 脚本,因此它可能是非常规的。I wanted an answer, myself. Try the following to output only deletes from
svn log
.This filters the log output through awk. awk buffers each revision line it finds, outputting it only when a delete record is found. Each revision is only output once, so multiple deletes in a revision are grouped together (as in standard
svn log
output).You can specify a
--limit
to reduce the amount of records returned. You may also remove the--stop-on-copy
, as needed.I know there are complaints about the efficiency of parsing the whole log. I think this is a better solution than grep and its "cast a wide net"
-B
option. I don't know if it is more efficient, but I can't think of an alternative tosvn log
. It's similar to @Alexander Amelkin's answer, but doesn't need a specific name. It's also my first awk script, so it might be unconventional.您可以使用二分搜索找到提供该文件的最新版本。
我为此创建了一个简单的
/bin/bash
脚本:You can find the last revision which provides the file using binary search.
I have created a simple
/bin/bash
script for this:我编写了一个 php 脚本,将所有存储库的 svn 日志复制到 mysql 数据库中。 我现在可以对我的评论或文件名进行全文搜索。
I wrote a php script that copies the svn log of all my repositories into a mysql database. I can now do full text searches on my comments or names of files.
当您想查看旧文件时,您确实应该知道以下之间的区别:
和
第一个版本查看现在可用的路径 http://server/svn/project/file 并检索该文件,因为它是修订版 1234 中的版本。(因此,此语法在之后不起作用文件删除)。
第二种语法获取修订版中作为 http://server/svn/project/file 提供的文件1234. 所以这个语法确实适用于已删除的文件。
您甚至可以组合这些方法来检索修订版 2345 中可用的文件 http://server/svn/project/文件,但其内容与 1234 中的内容相同:
When you want to look at old files you really should know the difference between:
and
The first version looks at the path that is now available as http://server/svn/project/file and retrieves that file as it was in revision 1234. (So this syntax does not work after a file delete).
The second syntax gets the file that was available as http://server/svn/project/file in revision 1234. So this syntax DOES work on deleted files.
You can even combine these methods to retrieve a file that was available in revision 2345 as http://server/svn/project/file but with the contents as it had in 1234 with:
首先,找到文件被删除的版本号:
然后在 log.txt(不是 SVN 大师,所以我不知道更好的方法)中查找包含 的行
,看看是哪个版本。 然后,与其他答案一样,使用以前的修订版恢复文件。
First, find the revision number where the file got deleted:
Then look in log.txt (not an SVN guru, so I don't know a better way) for a line with
and see which revision that was. Then, as in the other answers, resurrect the file using the previous revision.
要获取已删除文件的日志,请使用
如果您想恢复文件并保留其版本历史记录,请使用
如果您只想要文件内容但未版本化(例如,为了快速检查),请使用
在任何情况下,请勿使用'svn up' 恢复已删除的文件!
To get the log of a deleted file, use
If you want to resurrect the file and keep its version history, use
If you just want the file content but unversioned (e.g., for a quick inspection), use
In any case, DO NOT use 'svn up' to get a deleted file back!
git 中并没有什么特别的。 如果您知道文件的名称,则可以通过日志找到删除它的更改:
然后您可以使用该提交来获取删除之前存在的文件。
示例:
请注意,这实际上并没有将文件放回到版本控制中。 它只是将文件以其最终状态存在到当前位置。 然后您可以添加它或只是检查它或从那时起进行任何操作。
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:
Then you can use that commit to get the file as it existed before the deletion.
Example:
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.