如果禁止版本控制关键字,如何防止文件混淆?

时间:2023-02-05 14:30:02

At least two brilliant programmers, Linus Torvalds and Guido von Rossum, disparage the practice of putting keywords into a file that expand to show the version number, last author, etc.

至少有两位出色的程序员,Linus Torvalds和Guido von Rossum,贬低了将关键字放入文件中的做法,该文件扩展为显示版本号,最后一位作者等。

I know how keyword differences clutter up diffs. One of the reasons I like SlickEdit's DiffZilla is because it can be set to skip leading comments.

我知道关键字差异是如何混乱的。我喜欢SlickEdit的DiffZilla的原因之一是因为它可以设置为跳过引导注释。

However, I have vivid memories of team-programming where we had four versions of a file (two different releases, a customer one-off, and the development version) all open for patching at the same time, and was quite helpful to verify with a glance that each time we navigated to an included header we got the proper one, and each time we pasted code the source and destination were what we expected.

但是,我对团队编程有着生动的回忆,我们有四个版本的文件(两个不同的版本,一个客户一次性和开发版本)都可以同时打开补丁,并且非常有用一目了然,我们每次导航到包含的标题时都得到了正确的标题,每次我们粘贴代码时,源和目标都是我们所期望的。

There is also the where-did-this-file-come-from problem that arises when a hasty developer copies a file from one place to another using the file system, rather than checking it out of the repository using the tool; or, more defensibly, when files under control in locations A, B, and C need to be marshalled (with cherry-picking) into a distribution location D.

当一个仓促的开发人员使用文件系统将文件从一个地方复制到另一个地方而不是使用该工具将其从存储库中检出时,也会出现这个文件来自何处的问题;或者,更可靠的是,当位置A,B和C中受控制的文件需要编组(采摘樱桃)到分发地点D.

In places where VCS keywords are banned, how do you cope?

在禁止使用VCS关键字的地方,您如何应对?

2 个解决方案

#1


This doesn't exactly answer your question, but I imagine Linus and Guido have reasons for disliking keywords that don't apply to small-team corporate development.

这并不完全回答你的问题,但我想Linus和Guido有理由不喜欢不适用于小团队企业发展的关键词。

An $Id$ tag for instance, has what you could consider to be a global version number. Linux and I guess also Python development is fragmented enough that no number can be global. Lots of people have their own repositories all over the place that would fill in their own $Id$ values and then those patches might be sent to Linus or Guido's repositories where they don't make any sense.

例如,$ Id $标签具有您可以认为是全局版本号的内容。 Linux和我猜想Python开发也很分散,没有数字可以全局化。很多人都有自己的存储库,可以填写他们自己的$ Id $值,然后这些补丁可能会被发送到Linus或Guido的存储库,在那里他们没有任何意义。

However, in your environment, you probably have one central repository which would assign these and it would be fine. Sounds like you're using git. I wonder if it's possible to configure the central git repository to do tag substitution while the local developer repositories don't. Or perhaps it's better to get the commit hash in the tag.

但是,在您的环境中,您可能有一个*存储库,可以分配这些,并且没问题。听起来你正在使用git。我想知道是否可以配置*git存储库来执行标记替换,而本地开发人员存储库则不然。或者最好在标记中获取提交哈希值。

#2


I've never used VCS keywords in my entire career, over 30 years. From the most primitive VCS system I've used, up to the present (TFS), I've used some other structure to understand "where I am".

30多年来,我从未在整个职业生涯中使用过VCS关键词。从我使用过的最原始的VCS系统到现在(TFS),我已经使用了一些其他结构来理解“我在哪里”。

I am rarely in a situation where I've only got one file to work with. I've usually got all the other files necessary to build the project or set of projects. I usually use branching (or streams on one occasion), and I'm working on some slice of the given branch or stream.

在我只有一个文件可以使用的情况下,我很少。我通常拥有构建项目或项目集所需的所有其他文件。我通常使用分支(或一次使用流),我正在处理给定分支或流的某些片段。

If I'm working on multiple branches or streams, I'll have one directory tree for each. All I need to do to know what file I'm working on is check the file path, at the very worst.

如果我正在处理多个分支或流,我将为每个分支或流创建一个目录树。我需要做的就是知道我正在处理的文件是检查文件路径,最糟糕的情况。

At the very best, the version control system will tell you exactly which version of the file you're working on, what the change history is, who else is working on different versions of the file, and anything else you'd care to know.

在最好的情况下,版本控制系统会告诉您正在处理的文件版本,更改历史记录是什么,还有谁在处理不同版本的文件,以及您需要知道的任何其他内容。

#1


This doesn't exactly answer your question, but I imagine Linus and Guido have reasons for disliking keywords that don't apply to small-team corporate development.

这并不完全回答你的问题,但我想Linus和Guido有理由不喜欢不适用于小团队企业发展的关键词。

An $Id$ tag for instance, has what you could consider to be a global version number. Linux and I guess also Python development is fragmented enough that no number can be global. Lots of people have their own repositories all over the place that would fill in their own $Id$ values and then those patches might be sent to Linus or Guido's repositories where they don't make any sense.

例如,$ Id $标签具有您可以认为是全局版本号的内容。 Linux和我猜想Python开发也很分散,没有数字可以全局化。很多人都有自己的存储库,可以填写他们自己的$ Id $值,然后这些补丁可能会被发送到Linus或Guido的存储库,在那里他们没有任何意义。

However, in your environment, you probably have one central repository which would assign these and it would be fine. Sounds like you're using git. I wonder if it's possible to configure the central git repository to do tag substitution while the local developer repositories don't. Or perhaps it's better to get the commit hash in the tag.

但是,在您的环境中,您可能有一个*存储库,可以分配这些,并且没问题。听起来你正在使用git。我想知道是否可以配置*git存储库来执行标记替换,而本地开发人员存储库则不然。或者最好在标记中获取提交哈希值。

#2


I've never used VCS keywords in my entire career, over 30 years. From the most primitive VCS system I've used, up to the present (TFS), I've used some other structure to understand "where I am".

30多年来,我从未在整个职业生涯中使用过VCS关键词。从我使用过的最原始的VCS系统到现在(TFS),我已经使用了一些其他结构来理解“我在哪里”。

I am rarely in a situation where I've only got one file to work with. I've usually got all the other files necessary to build the project or set of projects. I usually use branching (or streams on one occasion), and I'm working on some slice of the given branch or stream.

在我只有一个文件可以使用的情况下,我很少。我通常拥有构建项目或项目集所需的所有其他文件。我通常使用分支(或一次使用流),我正在处理给定分支或流的某些片段。

If I'm working on multiple branches or streams, I'll have one directory tree for each. All I need to do to know what file I'm working on is check the file path, at the very worst.

如果我正在处理多个分支或流,我将为每个分支或流创建一个目录树。我需要做的就是知道我正在处理的文件是检查文件路径,最糟糕的情况。

At the very best, the version control system will tell you exactly which version of the file you're working on, what the change history is, who else is working on different versions of the file, and anything else you'd care to know.

在最好的情况下,版本控制系统会告诉您正在处理的文件版本,更改历史记录是什么,还有谁在处理不同版本的文件,以及您需要知道的任何其他内容。