通过符号链接引用时无法提交 svn 控制的目录
我有一个问题,我在另一个问题中描述得很差。我发布此内容是为了更清楚地说明我想要做什么以及我遇到了什么问题。有一个高票数的答案,但它实际上并没有解决我的问题(简短的故事:我不是试图将符号链接目录添加到我的版本控制项目中)。
如果您已经知道 subversion 是如何工作的,请跳到下面以获得实际问题。
我在命令行中,当前工作目录是我的主目录。
$> pwd
/home/user
我有一个 svn 项目。假设它名为 some_project
。我想将项目签出到 real_directory/
。
$> svn checkout http://svnhost.net/some_project real_directory
A real_directory/index.php
...
A real_directory/robots.txt
Checked out revision 1143.
我还没有cd
进入该目录;我仍然在它之外,在我的主目录中: $>密码 /home/user
然而,我仍然可以在文件 real_directory/
上使用 svn 命令,即使它不是我当前的工作目录,
$> svn status real_directory/
$> touch real_directory/new_file.txt
$> svn status real_directory/
? real_directory/new_file.txt
$> svn add real_directory/new_file.txt
A real_directory/new_file.txt
我指出这一点是为了澄清另一个问题中提出的误解。请注意,我向项目添加了一个文件,但仍在版本控制目录之外。我可以这样做是因为 real_directory
目录中存在 .svn/
目录。这就是为什么 real_directory/
包含 some_project
subversion 项目,即使它有不同的名称。
$> ls real_directory/.svn
all-wcprops entries format prop-base props text-base tmp
(如果您已经知道这一点,请耐心等待 - 我最初的问题有一个投票良好的答案,它给出了有关使用 subversion 执行此操作的能力的错误信息!)
这是 svn 的语法命令:
svn [svn-controlled directory] command
如果您不指定目录,svn 将假定您正在谈论当前目录。因此,所有这些都是等效的(当前工作目录位于 shell 提示符中):
[ /home/user ]$ svn status real_directory/
A real_directory/new_file.txt
[ /home/user ]$ cd real_directory/
[ /home/user/real_directory ]$ svn status .
A new_file.txt
[ /home/user/real_directory ]$ svn status
A new_file.txt
因此,回顾一下:我可以在不在版本控制目录内时做任何我想做的事情,就像我一样在其中,只需在我发出 svn 命令时指定目录即可。
好吧,现在这已经了,问题来了:
当我创建一个指向 subversion 控制目录的符号链接时,svn 会识别它以执行诸如 add 之类的命令
和 status
,但不适用于commit
!
当我添加文件并询问其状态时,符号链接目录的工作方式与真实目录一样:
$> svn status real_directory/
A real_directory/new_file.txt
$> ln -s real_directory/ symlink
$> svn status symlink
A symlink/new_file.txt
$> svn status real_directory/
A real_directory/new_file.txt
$> touch symlink/another_new_file.txt
$> svn status symlink
? symlink/another_new_file.txt
A symlink/new_file.txt
$> svn add symlink/another_new_file.txt
A symlink/another_new_file.txt
$> svn status symlink/
A symlink/another_new_file.txt
A symlink/new_file.txt
查看 symlink/
的行为方式与 real_directory/
的目的相同添加和状态
? 问题:提交命令失败:
$> svn commit symlink/ -m "test commit"
svn: '/home/user' is not a working copy
svn: Can't open file '/home/user/.svn/entries': No such file or directory
嗯?这很奇怪。当我执行 status
和 add
时,Svn 当然认为该文件存在!也许它被删除了?
$> ls symlink/.svn/entries
symlink/.svn/entries
不,还在那里。里面还有数据吗?
$> ls -lha !$
ls -lha symlink/.svn/entries
-r--r--r-- 1 user group 14K 2009-12-18 06:36 symlink/.svn/entries
是啊,好像还可以吧!好吧,忘记尝试通过符号链接提交目录。只用真实名称提交目录怎么样?
$> svn commit real_directory/ -m "test commit"
Adding real_directory/another_new_file.txt
Adding real_directory/new_file.txt
Transmitting file data ..
Committed revision 1144.
工作正常。为什么 svn 可以在符号链接目录上使用 add
和 status
,但不能使用 commit
?
I have a problem that I describe poorly in another question. I'm posting this to make it more clear what I want to do, and what problem I'm encountering. There is a highly-voted answer, but it doesn't actually address my problem (short story: I'm not trying to add a symlinked directory to my version-controlled project).
If you already know how subversion works, skip to below to get the actual question.
I am at the command line, and the current working directory is my home directory.
gt; pwd
/home/user
I have an svn project. Let's say it's called some_project
. I want to check the project out to real_directory/
.
gt; svn checkout http://svnhost.net/some_project real_directory
A real_directory/index.php
...
A real_directory/robots.txt
Checked out revision 1143.
I haven't cd
ed into that directory; I'm still outside of it, in my home directory:
$> pwd
/home/user
Yet I can still use svn commands on files real_directory/
, even though it's not my current working directory
gt; svn status real_directory/
gt; touch real_directory/new_file.txt
gt; svn status real_directory/
? real_directory/new_file.txt
gt; svn add real_directory/new_file.txt
A real_directory/new_file.txt
I'm pointing this out to clarify misconceptions presented in the other question. Note that I added a file to the project, while still outside of the version-controlled directory. I can do this because of the existence of the .svn/
directory in the real_directory
directory. This is what makes real_directory/
contain the some_project
subversion project, even though it has a different name.
gt; ls real_directory/.svn
all-wcprops entries format prop-base props text-base tmp
( If you already know this, please bear with me -- my original question had a well-voted answer that gave wrong information about the ability to do this with subversion! )
This is the syntax of the svn
command:
svn [svn-controlled directory] command
If you don't specify the directory, svn will assume you're talking about the current directory. So all of these are equivalent (current working directory is in the shell prompt):
[ /home/user ]$ svn status real_directory/
A real_directory/new_file.txt
[ /home/user ]$ cd real_directory/
[ /home/user/real_directory ]$ svn status .
A new_file.txt
[ /home/user/real_directory ]$ svn status
A new_file.txt
So, to recap: I can do anything I want while not inside the version controlled directory, just as if I were inside of it, simply by specifying the directory when I issue my svn commands.
OK, now that that's out of the way, here's the problem:
When I create a symlink to the subversion controlled directory, svn recognizes it for commands such as add
and status
, but not for commit
!
Here is the symlink directory working just like the real directory when I add files and ask its status:
gt; svn status real_directory/
A real_directory/new_file.txt
gt; ln -s real_directory/ symlink
gt; svn status symlink
A symlink/new_file.txt
gt; svn status real_directory/
A real_directory/new_file.txt
gt; touch symlink/another_new_file.txt
gt; svn status symlink
? symlink/another_new_file.txt
A symlink/new_file.txt
gt; svn add symlink/another_new_file.txt
A symlink/another_new_file.txt
gt; svn status symlink/
A symlink/another_new_file.txt
A symlink/new_file.txt
See how symlink/
acts just like real_directory/
for the purposes of add
and status
? Problem: this fails on the commit command:
gt; svn commit symlink/ -m "test commit"
svn: '/home/user' is not a working copy
svn: Can't open file '/home/user/.svn/entries': No such file or directory
Huh? That's weird. Svn certainly thinks that file exists when I do status
and add
! Maybe it got deleted?
gt; ls symlink/.svn/entries
symlink/.svn/entries
Nope, still there. Does it still have data in it?
gt; ls -lha !$
ls -lha symlink/.svn/entries
-r--r--r-- 1 user group 14K 2009-12-18 06:36 symlink/.svn/entries
Yup, seems to be okay! Alright, forget trying to commit the directory by its symlink. What about just committing the directory by its real name?
gt; svn commit real_directory/ -m "test commit"
Adding real_directory/another_new_file.txt
Adding real_directory/new_file.txt
Transmitting file data ..
Committed revision 1144.
Works fine. Why does svn work with add
and status
on a symlinked directory, but not commit
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发布到邮件列表并得到了很好的答案。
由于符号链接实际上是一个文件系统文件,所以发生的情况是 svn 认为我正在尝试将符号链接作为文件提交给当前目录中的项目 - 基本上就是我最初认为我想要的做!
正确的做法是
I posted to the mailing list and got a good answer.
Since the symlink is actually a filesystem file, what's happening is that svn thinks that I'm trying to commit that symlink as a file for a project in the current directory -- basically what Ire originally thought I wanted to do!
The proper thing to do is