如何将以编程方式生成的新文件添加到源代码管理中?

发布于 2024-08-23 12:54:13 字数 449 浏览 3 评论 0原文

这是我从未真正理解过的源代码控制,特别是 Subversion(我曾经使用过的唯一源代码控制,这并没有说明太多)。我正在考虑转向 git 或 Mercurial,所以如果这影响我的问题的答案,请指出。

好的。据我了解,每次创建新文件时,我都必须告诉 SVN,以便它知道将其添加到存储库并将其置于控制之下。类似这样:

svn add newfile

如果我是创建该文件的人,那很好:我知道我创建了它,我知道它的名称,我知道它位于哪里,所以很容易告诉 SVN 它。

但现在假设我正在使用某种框架,例如 Rails、Django、Symfony 等,并且假设我已经完成了初始提交。所有这些框架都以编程方式创建新文件,通常一次创建多个文件,在不同的目录中等等。我如何告诉源代码管理这些新文件?我是否必须逐一查找并添加它们?有更简单的方法吗? (或者我可能误解了有关源代码控制的一些基本知识?)

This is something I've never really understood about source control, specifically Subversion (the only source control I've ever used, which isn't saying much). I'm considering moving to git or Mercurial, so if that affects the answer to my question, please indicate as such.

Ok. As I understand it, every time I create a new file, I have to tell SVN about it, so that it knows to add it to the repository and place it under control. Something like:

svn add newfile

That's fine if I'm the one creating the file: I know I created it, I know its name, I know where it lives, so it's easy to tell SVN about it.

But now suppose I'm using a framework of some kind, like Rails, Django, Symfony, etc., and suppose I've already done the initial commit. All of these frameworks create new files programmatically, often many at once, in different directories, etc. etc. How do I tell the source control about these new files? Do I have to hunt each one of them down individually and add them? Is there an easier way? (Or am I possibly misunderstanding something fundamental about source control?)

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

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

发布评论

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

评论(2

相思故 2024-08-30 12:54:13

一般来说,如果文件可以从项目中的其他文件生成,则不应将它们添加到源代码管理中。确实,在某些情况下,最初会生成文件,但必须手动修改。在这种情况下,您必须将其添加到源代码管理中。但是,您几乎不应该自动添加文件。

Generally speaking, you shouldn't add files to source control if they can be generated from other files in your project. It's true that in some cases, a file is initially generated, but must be modified manually. In that case you will have to add it to source control. However, you should almost never automatically add files.

绅刃 2024-08-30 12:54:13

我总体上同意马修的观点,如果可以生成它,则不应添加它,而应保持动态创建。

对于添加多个文件的实际问题,我不记得在 svn 中(尽管我认为应该是可能的),但是要在 git 中执行此操作:

  • 使用 git bash (命令行)您可以添加所有“松散”文件通过在 add 命令后不指定文件,可以添加目录或子目录下的文件。您还可以将 git 设置为忽略某些文件,这样在这种情况下就不会添加它们。

  • 另一种方法是使用 git gui,它显示所有未跟踪的文件,您可以选择所有文件(或其中的组)并单击添加它们。

I agree with Matthew in general, if it can be generated it shouldn't be added but remain dynamically created.

For the practical question of adding multiple files, I don't remember in svn (though I think it should be possible), but to do this in git:

  • Using git bash (command line) you can add all "loose" files under the directory or subdirectory by not specifying a file after the add command. You can also set git to ignore certain files, so they wont be added in that case.

  • Another way is using git gui, it displays all un-tracked files and you can select them all (or groups of it) and add them in one click.

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