简体   繁体   English

删除SVN提交的所有跟踪

[英]Delete all traces of a SVN commit

Someone in our team accidentally committed files containing a password to our repository. 我们团队中的某个人意外地将包含密码的文件提交到我们的存储库。 The password can't easily be changed. 密码不容易更改。

Is there a way, with full admin permissions, to delete all traces of this commit? 是否有一种方法,具有完全管理员权限,删除此提交的所有痕迹? I'm not talking about a revert or delete, which would obviously keep the password in the file history. 我不是在谈论恢复或删除,这显然会将密码保存在文件历史记录中。

Yes, but it is not for the faint of heart. 是的,但这不适合胆小的人。 You have to use svnadmin dump and svnadmin load to recreate your repository. 您必须使用svnadmin dumpsvnadmin load来重新创建存储库。

If you choose to do this, the first step is to stop your users from committing , and make a backup of your repository. 如果您选择这样做,第一步是阻止您的用户提交 ,并备份您的存储库。 I also recommend walking through the steps on a copy of your repository; 我还建议您浏览一下存储库的副本; you can use rsync to copy the entire repository directory into a temporary directory, and work from there. 您可以使用rsync将整个存储库目录复制到临时目录中,并从那里开始工作。

For these instructions, I'm going to create a new repository in a temporary directory: 对于这些说明,我将在临时目录中创建一个新的存储库:

tmp, 502> svnadmin create example.repo
tmp, 503> svn co file://`pwd`/example.repo example
Checked out revision 0.

I created a file that contained four revisions, the 3rd of which needs to be deleted: 我创建了一个包含四个修订的文件,其中第三个需要删除:

example, 536> svn log test.txt 
------------------------------------------------------------------------
r4 | kgregory | 2011-04-06 08:46:59 -0400 (Wed, 06 Apr 2011) | 1 line

post-bad commit
------------------------------------------------------------------------
r3 | kgregory | 2011-04-06 08:46:42 -0400 (Wed, 06 Apr 2011) | 1 line

bad revision
------------------------------------------------------------------------
r2 | kgregory | 2011-04-06 08:46:28 -0400 (Wed, 06 Apr 2011) | 1 line

good revision
------------------------------------------------------------------------
r1 | kgregory | 2011-04-06 08:46:02 -0400 (Wed, 06 Apr 2011) | 1 line

initial revision
------------------------------------------------------------------------

So, we need to dump revisions both before and after the bad one, using the -r flag to specify revision ranges. 因此,我们需要在错误之前和之后转储修订,使用-r标志指定修订范围。 The --incremental flag on the second dump is important, because it will tell the load command not to create a new file. 第二个转储上的--incremental标志很重要,因为它会告诉load命令不要创建新文件。

Note that I'm running these commands from the same directory that holds the repository. 请注意,我从保存存储库的同一目录运行这些命令。

svnadmin dump -r 1:2 example.repo/ > pred.svndump
* Dumped revision 1.
* Dumped revision 2.
tmp, 552> svnadmin dump -r 4:4 --incremental example.repo/ > succ.svndump
* Dumped revision 4.

Now move the original repository out of the way, and create an empty repository with the same name: 现在将原始存储库移开,并创建一个具有相同名称的空存储库:

tmp, 540> mv example.repo example.repo.bak
tmp, 541> svnadmin create example.repo

And import the contents of the dump files. 并导入转储文件的内容。

tmp, 569> svnadmin --quiet load example.repo < pred.svndump 
tmp, 570> svnadmin --quiet --ignore-uuid load example.repo < succ.svndump 

Now tell everyone to delete their working directories and check out fresh. 现在告诉大家删除他们的工作目录并查看新的。 And you should see the following log: 你应该看到以下日志:

example, 574> svn log test.txt 
------------------------------------------------------------------------
r3 | kgregory | 2011-04-06 08:46:59 -0400 (Wed, 06 Apr 2011) | 1 line

post-bad commit
------------------------------------------------------------------------
r2 | kgregory | 2011-04-06 08:46:28 -0400 (Wed, 06 Apr 2011) | 1 line

good revision
------------------------------------------------------------------------
r1 | kgregory | 2011-04-06 08:46:02 -0400 (Wed, 06 Apr 2011) | 1 line

initial revision
------------------------------------------------------------------------

There is one HUGE caveat: this process assumes that there haven't been any commits to the file since the bad commit (ie, the successor dump only contains changes to other files). 有一个巨大的警告:此过程假定由于错误提交(即,后继转储仅包含对其他文件的更改),因此没有对文件进行任何提交。

If that's not the case, you can still delete the revision, but it's a lot more work. 如果情况并非如此,您仍然可以删除修订版,但这项工作要多得多。 You need to create a new check-in, containing a clean copy of the file along with any other files that were changed with it while bad. 您需要创建一个新的签到,其中包含该文件的干净副本以及随之更改的任何其他文件。 Then create multiple dumpfiles, excluding any revisions that contained the bad file. 然后创建多个dumpfile,排除包含坏文件的任何修订。

Finally: I strongly suggest several dry runs. 最后:我强烈建议几次干运行。 As you can see from the history numbers in my examples, I screwed up a few times. 从我的例子中的历史数字中可以看出,我搞砸了几次。 As I said at the beginning, it's easy to copy a Subversion repository into a temporary directory. 正如我在开始时所说的,将Subversion存储库复制到临时目录中很容易。 And when you do that, you can keep trying until you get it right, then just copy the fixed repository back into place. 当你这样做时,你可以继续尝试,直到你做对了,然后只需将固定的存储库复制回原位。

See the answer at the FAQ 请参阅常见问题解答中的答案

There are special cases where you might want to destroy all evidence of a file or commit. 在某些特殊情况下,您可能希望销毁文件或提交的所有证据。 (Perhaps somebody accidentally committed a confidential document.) This isn't so easy, because Subversion is deliberately designed to never lose information. (也许有人意外地提交了一份机密文件。)这并不容易,因为Subversion是故意设计的,永远不会丢失信息。 Revisions are immutable trees which build upon one another. 修订是不可变的树,彼此建立在一起。 Removing a revision from history would cause a domino effect, creating chaos in all subsequent revisions and possibly invalidating all working copies. 从历史记录中删除修订版会导致多米诺骨牌效应,在所有后续修订版中产生混乱,并可能使所有工作副本无效。

The project has plans, however, to someday implement an svnadmin obliterate command which would accomplish the task of permanently deleting information. 然而,该项目计划有一天实施一个svnadmin obliterate命令,该命令将完成永久删除信息的任务。 (See issue 516.) (见问题516.)

In the meantime, your only recourse is to svnadmin dump your repository, then pipe the dumpfile through svndumpfilter (excluding the bad path) into an svnadmin load command. 与此同时,您唯一的办法是svnadmin转储您的存储库,然后通过svndumpfilter(不包括坏路径)将转储文件传输到svnadmin load命令中。 See chapter 5 of the Subversion book for details about this. 有关详细信息,请参阅Subversion书的第5章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM