我已开始使用版本控制来更好地管理 PowerShell 代码的修订。我决定使用 Mercurial 有 3 个主要原因:
- 作为 DVCS,它不需要服务器。
- 如果我愿意,我可以免费在线存储一个私有存储库(bitbucket.org),
- 它似乎比 Git 使用起来更简单。
Mercurial 非常适合对 PowerShell 模块进行版本控制,因为每个模块都包含在其自己的目录中。但是,我有一些不属于模块的脚本,但我仍然想对它们进行版本控制。这些脚本位于添加到 $env:PATH 的“.\Scripts”目录中,因此我可以轻松地从命令行运行它们。由于这些脚本彼此之间并不真正相关,因此为 Scripts 目录创建单个存储库没有多大意义。
我应该如何对单个脚本进行版本控制?
我想到了以下选项:
- 为每个脚本/相关脚本创建子目录。
- 使用临时存储库,直到脚本“稳定”,然后将脚本添加到主“脚本”目录并将脚本集合作为一个版本。这将减少引入“脚本”存储库的变更集数量。
有没有一个工具可以更好地处理单个文件的版本控制?有没有更好的方法使用 Mercurial 对单个文件进行版本控制?还有其他想法吗?
I've started using version control to better manage revisions to my PowerShell code. I decided to use Mercurial for 3 main reasons:
- As a DVCS, it doesn't require a server.
- If I want to, I can store a private repository online for free (bitbucket.org)
- It seemed simpler to use than Git.
Mercurial works well for versioning PowerShell Modules since each module is contained in its own directory. However, I have some scripts that don't belong in a module, but I would still like to version them. These scripts are in a ".\Scripts" directory that is added to $env:PATH
so I can easily run them from the command line. Since these scripts aren't really related to each other, it doesn't make much sense to create a single repository for the Scripts directory.
How should I version single scripts?
I've thought of the following options:
- Create subdirectory for each script/related scripts.
- Use temporary repositories until the script is "stable" then add the script to the main "Scripts" directory and version the collection of scripts as one. This would reduce the number of changesets introduced to the "Scripts" repository.
Is there a tool that better handles versioning single files? Is there better way for versioning single files with Mercurial? Any other ideas?
发布评论
评论(3)
根据文件功能对文件进行分组应基于
1) 名称。
2) 它们所在的文件夹。
只需为脚本指定一个适当的名称即可。如果有多个相关脚本,则将它们分组到一个文件夹中。每个文件夹只有一个脚本是没有意义的。您最终会得到与脚本数量几乎相同的文件夹。
所有这些都在一个存储库中。通常,人们在一个存储库中拥有多个项目。创建多个存储库,尤其是对于几个文件来说意味着大量的开销。如果脚本不是“稳定”,请使用分支。这就是它们的用途并将它们合并回来。
并且不用担心存储库中有多少“变更集”!
PS:可能看起来有点固执己见,但对于你所问的问题,没有真正正确或错误的答案。
Grouping of files based on their functionality should be based on
1) Name.
2) Folder they are in.
Just give a proper name for the scripts. If there are multiple related scripts group them into a folder. Having one script per folder makes no sense. You end up with almost same number of folders as scripts.
All this in a single repository. Generally, people have multiple projects in a single repo. Creating multiple repos, especially for a few files means lots of overhead. If the script is not "stable" use branches. That is what they are for and merge them back.
And don't worry how many "changesets" are there in the repo!
PS: Might seem a bit opinionated, but there is no real right or wrong answer for what you ask.
退一步,放松,问问自己这是否是过早优化。使用 VCS 的主要好处是您不必需要担心从“完美”解决方案开始。 DVCS 跟踪跨重命名和更改的更改历史记录移动(使用
hg mv
,或尝试使用hg addremove --similarity
进行自动检测)。如果脚本全部位于同一目录中,那么当然有意义在同一个存储库中跟踪它们。
“临时”存储库违背了存储库的目的,即具有更改历史记录。
正如 @manojlds 所说,没有理由担心变更集的数量。没有任何。
我的建议:
./Scripts/incubating/
等目录中./Scripts/
或./Scripts /Foo/
或其他; 使用hg mv
帮助Mercurial跟踪移动/重命名hg addremove --similarity
自动检测移动/重命名Step back, relax, and ask yourself if this is premature optimization. A primary benefit of using VCS is that you do not need to worry about starting with the "perfect" solution. DVCS tracks change history across renames & moves (use
hg mv
, or try auto-detection withhg addremove --similarity
).If the scripts are all in the same directory, it certainly makes sense to track them in the same repository.
A "temporary" repo defeats the purpose of having a repo, which is to have a history of changes.
As @manojlds said, there is no reason to worry about the number of changesets. None.
My advice:
./Scripts/incubating/
./Scripts/
or./Scripts/Foo/
or whatever; usehg mv
to help Mercurial track the move/renamehg addremove --similarity
to auto-detect moves/renames我认为这里的小伙子有一些好主意,并指出您可能有点过于关注它。对于完全无忧无虑的源代码控制,请参阅 Tome 的指南 http://powertoe.wordpress.com/2010/12/12/why-every-it-pro-should-use-mercurial-for-source-control-with-their-powershell-scripts/
我遵循了这个方法,发现它非常有用。我发现源代码控制有用的两个原因:
度过了糟糕的一天并重写了脚本,这样它就不会执行您想要的任何操作,并且您不记得如何将其恢复!
需求的变化,有时你需要一个脚本来监控或做一些短期的事情,然后需要它恢复到原来的设置。使用源代码控制可以轻松完成。
因此,将所有脚本放在一个存储库中并不是真正的问题。
我确实想知道您是否也可以使用它来同步计算机(自动而不是在需要时推\拉),但这不是我有时间查看的东西。
I think the chaps here have some good ideas and have pointed out you may be focusing a little too much on it. For completely carefree source control see Tome's guide http://powertoe.wordpress.com/2010/12/12/why-every-it-pro-should-use-mercurial-for-source-control-with-their-powershell-scripts/
I've followed this method and found it very useful. 2 reasons I've found source control useful:
having a bad day and rewritten a script so that it doesn't do anything you want it to and you can't remember how to get it back!
changes in needs, sometimes you need a script to monitor or do something for a short period and then need it to revert to the original set up. easily done with source control.
As such, having all the scripts in one repo isn't really an issue.
I did wonder if you can use it to synchronise computers as well (automatically instead of pushing\pulling when needed) but it's not something I've had time to look at.