有没有办法从意外的“svn revert”中恢复?

发布于 2024-08-06 05:43:34 字数 480 浏览 4 评论 0原文

今天早上,我通过执行以下操作成功搬起石头砸了自己的脚:

  1. 开始对我的项目进行更改
  2. 对一堆文件进行大量编辑
  3. 意识到我的方法完全错误,我需要重新开始
  4. cd' d 到我的项目的顶层并执行“svn --recursive revert”。将我的本地沙箱恢复到更改前的状态。
  5. 当我意识到我的本地沙箱中还有许多其他未完成的更改时,我惊恐地嚎叫起来,而我刚刚将它们全部删除了。 (svn 服务器上周五宕机了,所以我无法签入它们,而且周末我已经忘记了它们)

幸运的是,在这种情况下,我在离开之前做了一个“svn diff > temp.txt”周五工作,temp.txt 文件仍在我的硬盘上,因此我能够将该文件输入“补丁”并恢复丢失的更改。

但为了我将来的参考(即下次我犯同样的愚蠢错误时)......有什么方法可以告诉 svn 撤消“svn revert”? svn 是否在任何地方保留本地/未签入差异的备份?

I managed to shoot myself in the foot this morning by doing the following:

  1. Started working on a change to my project
  2. Made a bunch of edits to a bunch of files
  3. Realized that my approach was all wrong, and that I needed to start over
  4. cd'd to the top level of my project and did a "svn --recursive revert ." to restore my local sandbox to its pre-changes state.
  5. Howled in horror as I realized that there had been a number of other changes outstanding in my local sandbox, and I had just obliterated all of them. (the svn server had been down last Friday so I hadn't been able to check them in, and I had forgot about them over the weekend)

Fortunately in this case I had done an "svn diff > temp.txt" before leaving work on Friday, and the temp.txt file was still on my hard drive, so I was able to feed that file into "patch" and recover my lost changes.

But for my future reference (i.e. the next time I make the same dumb mistake)... is there any way to tell svn to undo an "svn revert"? Does svn keep a backup of the local/not-checked-in diffs anywhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

谁把谁当真 2024-08-13 05:43:34

有一个解决方案...
转到回收站,您会在那里找到已删除文件的最新版本。
Tortoise 将其还原的每个文件“扔”到回收站。

There is a solution...
go to your recycle bin you'll find there the latest version of the deleted file.
Tortoise "throwing" to the recycle bin every file that it revert.

浮萍、无处依 2024-08-13 05:43:34

不,(绝对)

如果你对 Subversion 说它应该恢复一个文件,那么所有的更改都会消失。

只有你的记忆才能把它们找回来。

例外:您添加的新文件,只会失去“已添加”状态,但文件将保留在此目录中,只是状态未知(“?”)

平台/软件例外: 在 Windows 上使用 TortoiseSVN,Revert 首先将文件放入回收站,然后再还原它们。您可以深入回收站来恢复文件。

No, (absolutely) NO.

If you say to Subversion it should revert a file, all changes are gone by the wind.

Only your memory can get them back.

Exception: New files you had added, will only lose their status "added", but the file will remain in this directory, only status is unknown("?")

Platform / Software exception: Using TortoiseSVN on Windows, Revert first throws the files into Recycle Bin and then reverts them. You can dig into the Recycle Bin to recover the files.

〆凄凉。 2024-08-13 05:43:34

并不是真正特定于 Subversion,但如果您正在使用 Eclipse,您可以在本地历史记录中碰碰运气。

现在,有一些更特定于 Subversion 的内容:如果您不想为所做的每个更改创建一个分支,您可以在本地检查几个主干(trunk-modif-1、trunk-modif-2.. .)。每个“修改”都是在一个单独的树上完成的,您只需要保留一个列表,其中哪些签出对应于哪些修改。

或者你可以在本地使用 Git,但我从未尝试过。

Not really Subversion specific, but if you're working with Eclipse, you can try your luck in the local history.

Now, something a little bit more Subversion specific: if you don't want to make a branch for every change you do, you can keep a couple of trunk checked out locally (trunk-modif-1, trunk-modif-2...). Each "modification" is done on a separate tree and you only need to keep a list of which check out correspond to which modification.

Or you could use Git locally but I never tried it.

記柔刀 2024-08-13 05:43:34

最近犯了一个错误,没有将新的文件更改(大约 10 个)提交到 SVN 上,由于我的愚蠢错误,它们全部消失了。但拯救我的是 Windows 上下文菜单中的“恢复以前的版本”选项。唷,这真是一种解脱,也吸取了教训。

Recently did this mistake of not committing new file changes (about 10) onto SVN and they all vanished because of my silly mistake. But what saved me was the windows "Restore previous versions" option in the context menu. Phew that was a relief and lesson learnt.

夜夜流光相皎洁 2024-08-13 05:43:34

如果您使用svn 命令行客户端,则无法恢复文件。

但如果您使用 TortoiseSVN 作为 svn 客户端,您可以恢复它们。 TortoiseSVN 会自动将它们移动到您的回收站。您可以在意外恢复后从那里恢复它们。

这是 TortoiseSVN 中的一个可配置选项。它位于设置 -> 下对话框1->还原时使用回收站。

默认情况下选中,这意味着文件将移至回收站。如果您愿意(大多数情况下您不关心禁用此功能。如果您有理由,也请告诉我)

You can't recover the files, if you are using svn command-line client.

But you can recover them, if you are using TortoiseSVN as your svn client. TortoiseSVN will automatically move them to your Recycle Bin. You can restore them from there after an accidental revert.

This is a configurable option in TortoiseSVN. It is under Settings -> Dialog 1 -> Use recycle bin when reverting.

By default it is checked, which means files are moved to recycle bin. If you want(mostly you don't care to disable this. If you have a reason, please let me also know)

浮华 2024-08-13 05:43:34

如果您正在使用 InteliJ 那么您是一个幸运的人。在顶部菜单上,您有一个版本控制选项,在它下面您将找到本地历史记录选项,您可以在其中找到所选文件的所有历史记录,包括您对该文件执行的所有操作(更新、提交、恢复)。

祝你好运,
阿克德

If you are using InteliJ then you are a lucky person. On the top menu, you have a Version Control option, and under it you will find local history option, where you will find all the history for selected file, including all the operation you did with that file (update,commit, revert ).

Good luck,
Arkde

不语却知心 2024-08-13 05:43:34

此外,如果您已恢复 .NET 代码(.cs 文件等),并且在恢复之前构建了应用程序,但在进行更改之后,您可以使用任何反射器工具从程序集文件中恢复更改以查看代码。

Also if you have reverted your .NET code (.cs files etc) and you've built your application before revert but after you've made changes, you could recover changes from assembly file using any of the reflector tools to view code.

韶华倾负 2024-08-13 05:43:34

我非常幸运地在 Eclipse 的历史浏览器中找到了该文件的本地更改日志(Local Revisions)。我一直在逐一检查差异,并在覆盖之前对文件进行了几次保存。

I was extremely lucky to find a local change log of the file (Local Revisions) in the history browser in Eclipse. I had been inspecting the differences one by one and I had made a couple of saves on the file before overwriting.

安稳善良 2024-08-13 05:43:34

我恢复了解决方案(Visual Studio + AnkhSVN )并丢失了一些文件的更改。我在回收站中找不到该文件。

但是:我使用 Handy Recovery 恢复了丢失的文件,即 SVN 在恢复时仅删除我的文件。

使用任何数据恢复软件来恢复恢复的文件(例如试用版Handy Recovery

I reverted solution (Visual Studio + AnkhSVN ) and lose changes of few files. I can't find the file in the recycle bin.

BUT: I recovered my losing files with Handy Recovery, i.e. SVN just delete my files on reverting.

Use any data recovery software to recovery reverted files(like trial Handy Recovery)

绝不服输 2024-08-13 05:43:34

不,SVN 不保留日志或备份(尽管其他答案中提到了 TortoiseSVN 的解决方案)。

但万一有人正在浏览答案并且没有注意到OP问题中的这条评论:

“幸运的是,在这种情况下,我做了一个“svn diff >”周五下班前“temp.txt”,并且 temp.txt 文件仍在我的硬盘上,因此我能够将该文件输入“补丁”并恢复丢失的更改。”

我想在执行“svn revert”之前执行“svn diff”是一种常见的范例。如果您养成了这样做的习惯,即使差异只是回显到终端,您至少还有一种可能的途径来恢复丢失的更改。

No, SVN does not keep a log or backup (although there is a solution for TortoiseSVN noted in the other answers).

But in case someone is browsing the answers and did not notice this comment in the OP's question:

"Fortunately in this case I had done an "svn diff > temp.txt" before leaving work on Friday, and the temp.txt file was still on my hard drive, so I was able to feed that file into "patch" and recover my lost changes."

I imagine it is a common paradigm to do 'svn diff' BEFORE you do an 'svn revert'. If you get in the habit of doing this, even if the diff is just echoed to the terminal, you've at least got one possible avenue to recover your lost changes.

猫七 2024-08-13 05:43:34

截至 2024 年,如果您像我一样使用 TortoiseSVN,只需打开“显示日志”选项即可查看包含您删除的文件的文件夹的历史记录。然后您可以复制已删除文件的源代码。我不小心将文件移动到新文件夹而不是恢复更改。该文件与新文件夹一起被删除。通过这样做,我再次获得了源代码。
查看更多信息请访问 tortoise 网站

右键单击打开显示日志选项窗口资源管理器中的文件目录

修订日志对话框

As of 2024, if you use TortoiseSVN like me, just open the Show log option to see the history of the folder contains the file you deleted. Then you can copy the source code of the deleted file. I accidentally moved the file to a new folder than reverted the changes. The file was deleted with the new folder. By doing this, I got the source code again.
See more at tortoise website

Open show log option by right-clicking the file directory in window explorer

Revision log dialog

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文