忽略内容更改文件后,将其推入GIT存储库后

发布于 2025-02-11 14:23:57 字数 576 浏览 0 评论 0原文

我有一个文件用户。每次运行测试套件时,此CSV文件都会更新。

  • 我不希望该文件在我的本地计算机中进行修改 每次运行测试套件时。在这种情况下,我认为我可以使用 命令

      git update-index  -  assume-hindanged [< file> ...]] 
     

参考:我可以'git Commits'a文件并忽略其内容更改吗?

  • 现在,假设另一个开发人员拉了我推动的所有更改。 当测试套件在他的计算机上运行时,相同的CSV不应显示为修改,并且该文件仍应在他的机器中。

我假设将文件添加到.gitignore中 。已经跟踪了。

关于如何实现这一目标有什么想法吗?

I have a file users.csv which is pushed to the repository. This csv file gets updated every time the test suite is run.

  • I don't want the file to be shown as modified in my local machine
    every time the test suite is run. In that case i assume i can use the
    command

    git update-index --assume-unchanged [<file> ...] 
    

Ref: Can I 'git commit' a file and ignore its content changes?

  • Now, assume that another developer pulled all the changes that i pushed. When the test suite is run on his machine, the same csv should not show as modified and the file should be still there in his machine.

I assume adding the file in .gitignore will not help since the file is already tracked.

Any idea on how to achieve this?

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

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

发布评论

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

评论(2

青衫负雪 2025-02-18 14:23:57

理想情况下,测试套件应:

  • 复制user.csv to user.csv.test中的user.csv.test

​存储库。

Ideally, the test suite should:

  • copy users.csv to user.csv.test (with user.csv.test in the .gitignore, so left as a private file)
  • modify user.csv.test

That way, you don't have to manage update-index on each developer repositories.

何以心动 2025-02-18 14:23:57

GIT特别没有提供忽略对跟踪文件的更改的方法。这是在git Faq 中彻底回答:

git不能提供这样做的方法。原因是,如果GIT需要覆盖此文件,例如在结帐期间,它不知道文件的更改是否珍贵并且应该保留,或者应该保留,或者它们是否无关紧要并且可以安全地销毁。因此,它必须采用安全的路线并始终保留它们。

试图尝试使用git Update-index的某些功能,即假设插入的和跳过工作的位置,但是这些功能不能适当地用于此目的,不应是使用这种方式。

您是正确的,.gitignore对已经跟踪的文件没有影响。

有几种方法可以避免在这里遇到问题。首先是将临时目录(或test/tmp)进行测试套件输入和输出以避免这是一个问题。这就是GIT所做的,其他几个项目也是如此。

您也可以将文件users.csv忽略并将真实文件移至其他位置,然后在使用前将其复制到位。然后,如果测试套件对其进行了修改,则在开发系统上不会有问题。

Git specifically doesn't offer a way to ignore changes to tracked files. This is thoroughly answered in the Git FAQ:

Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.

It’s tempting to try to use certain features of git update-index, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.

You are correct that .gitignore has no effect on files that are already tracked.

There are a couple ways you can avoid having a problem here. The first is to use a temporary directory (or an ignored directory like test/tmp) for your test suite input and output to avoid this being a problem. This is what Git does and several other projects do as well.

You could also leave the file users.csv ignored and move the real file to a different location, and then copy it into place before use. Then, if the test suite modifies it, it won't be a problem on development systems.

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