问题描述
这些说明有点令人生畏和混乱:http://svnbook.red-bean.com/en/1.0/ch04s04.html#svn-ch-4-sect-4.3.而且他们似乎也没有提到如果您在执行svn rm
"[1] 后还没有签入,这会简单得多.
These instructions are a little intimidating and confusing: http://svnbook.red-bean.com/en/1.0/ch04s04.html#svn-ch-4-sect-4.3 .And also they don't seem to mention that it's much simpler if you haven't yet checked in after doing the "svn rm
" [1].
所以我认为这是为那些在谷歌上搜索的人记录更简单答案的好地方.
So I thought this would be a good place to record a simpler answer for those googling for this.
[1] 对于 svn 新手来说,svn rm
"可能会立即破坏文件.我记得做 svn rm
认为这只会将它从源代码控制中删除,并且当文件本身实际上消失时会吓坏了.所以一个子问题是,从版本控制中删除文件而不实际删除本地副本的正确方法是什么?
[1] To an svn newbie, it might appear that "svn rm
" immediately destroys the file. I recall doing svn rm
thinking that would just remove it from source control and freaking out when the file itself actually disappeared. So a sub-question is, what's the right way to remove a file from version control without actually removing your local copy?
推荐答案
如果你刚刚做了
svn rm foo.txt
然后你可以简单地撤销它
then you can undo that with simply
svn revert foo.txt
如果您在执行svn rm
"后已经签入,那么您可以查看日志(svn log
),找到文件所在的最后一个修订版,并从那个版本中获取它.
If you already checked in after doing the "svn rm
" then you can look at the log (svn log
), find the last revision where the file existed, and grab it from that version.
一种方法是合并具有该文件的旧版本.假设当前修订版为 123,该文件的最后一个版本为 120,然后执行以下操作:
One way to do that is to merge in the old revision that has the file. Assuming the current revision is 123 and the last version with that file is 120, then do this:
svn merge -r123:120
也许先做一次试运行,以确保它不会做任何你不想做的事情:
Maybe first do a dry run to make sure it won't do anything you don't want:
svn --dry-run merge -r123:120
对于子问题,如何在不删除本地副本的情况下从 svn 中删除文件:
For the sub-question, how to remove a file from svn without removing the local copy:
svn rm foo.txt --keep-local
或者,当然,您可以在 svn rm'ing 之前复制到临时文件,然后再复制回来:
Or, of course, you could just copy to a temp file before svn rm'ing and then copy back:
cp foo.txt foo.txt-tmp
svn rm foo.txt
(svn ci -m "just removed foo.txt from the repository")
cp foo.txt-tmp foo.txt
这篇关于在 subversion 中取消删除文件的简单方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!