通过 Git 管理永远不会提交的文件

发布于 2024-10-12 19:01:25 字数 332 浏览 1 评论 0原文

我的机器上有一些文件始终与我们的 Git 存储库中的文件不同(一个 ASP web.config 文件,它与我们的生产服务器对我的本地机器具有不同的设置,以及一个用于报告服务的 .rds 文件,其中有我用于连接到我们的报告服务器的个人凭据)。在这种情况下,您对使用 Git 有什么建议?

我不想做的是每次提交时都隐藏这些文件。我也不想创建包含这两个文件的分支,因为每次提交时我都必须首先提交到主分支,然后从那里提交到我们使用的主 SVN 存储库。 忽略这些文件也不好,因为其他人可能会根据我的需要对它们进行更改。

作为最终结果,我希望能够随时提交所有内容,而不是总是将除这两个文件之外的其他所有内容添加到我的索引中。

I have a few files on my machine that will always be different from those that are in our Git repository (an ASP web.config file that has different settings for my local box from our production servers, and a .rds file for reporting services that has my individual credentials in it for connecting to our reporting server). What do you recommend for working with Git in this scenario?

What I don't want to do is stash these files every time I commit. Nor do I want to create a branch that contains these 2 files because then on every commit I have to first commit to the main branch and from there dcommit to the main SVN repo that we use.
It also wouldn't be good to ignore these files since others could make changes to them that I would need.

As a final result, I would like to be able to commit everything at any time instead of always adding everything else to my index except for these 2 files.

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

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

发布评论

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

评论(3

看轻我的陪伴 2024-10-19 19:01:25

涂抹/清理脚本是处理这个问题的方法。本质上,当它们被签出时,空连接字符串将被您的开发连接字符串替换。当您提交时,连接字符串将被第二个脚本“清理”,并且存储库具有带有空白字符串的版本。

替代文本

替代文本

现在,当您进行比较并且该文件中有更改时,它们将只是那些从未更改的文件。

然而,在部署时,我不会就此罢休。您希望部署 IT 系统部门处理的脚本,并且这些脚本不属于您的开发工作流程。

您可以在这里阅读更多相关信息: https:// git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion

希望这有帮助。

Smudge/clean scripts are the way to handle this. Essentially when they are checked out, the empty connection string is replaced by your dev connection string. When you commit, the connection string is "cleaned" by a second script and the repository has a version with a blank string.

alt text

alt text

Now when you do a diff and there are changes in that file, they will only be the ones that never change.

When deploying, I would not rest on this however. You want deploy scripts that IT Systems department handle and is out of your dev work flow.

you can read more about this here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Attributes#_keyword_expansion

hope this helps.

夏夜暖风 2024-10-19 19:01:25

我签入了常规配置文件,该文件是用非版本化的 .gitignore-d 本地配置进行修改的。这似乎是一种标准的做法。

I check in the general config file, which is amended with non-versioned, .gitignore-d local config. This seems to be a standard way of doing it.

三五鸿雁 2024-10-19 19:01:25

使用 .gitignore 文件并将其签入您的存储库。

http://git-scm.com/docs/gitignore

但是,请签入示例 Web。 config.sample 让新开发人员可以快速将文件复制为 web.config 来开始使用。您可能想在项目的根目录中编写一个简单的脚本或自述文件,向人们解释如何开始使用该项目。您还可以放置对项目不重要的其他用户特定文件,例如 .suo 文件。

Use a .gitignore file and check it into your repository.

http://git-scm.com/docs/gitignore

However, check in a sample web.config.sample that lets new developers to quickly copy the file as web.config to get started. You might want to write a simple script or a README file on the root of the project that explains people on how to get started with the project. You can also put other user specific files that are not important for the project like the .suo files.

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