如何冻结存储库中的文件 [英] How to freeze a file in a repository

查看:114
本文介绍了如何冻结存储库中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一种情况,我们的回购申请中的文件应该锁定到位,未来不会改变。



我将文件添加到 .gitignore ,但是当我在本地修改它时,git仍会跟踪它 - 我的现在的理解是,在它们已经在repo中后添加文件/文件夹到.gitignore不起作用,并且一种可能性是使用 git rm --cached file 来找不到它们。



如果我这样做了,该文件将不再可用于回购下一个克隆它的人吗?有没有更好的方法来冻结回购中的这个文件?

解决方案

git rm --cached file 该存储库,以便只存在当前工作目录中的未跟踪文件。未来的克隆将不会包含该文件。



Git并没有真正提供冻结文件的方法,因此无法修改。你可以做的最好的是创建一个预先提交的钩子,在提交之前重置文件,或者最好中止提交,直到你自己重置文件。


We've got a situation where a file in our repo should be locked in place, unchangeable going forward.

I've added the file to .gitignore but when I modify it locally git still tracks it-- my understanding now is that adding files/folders to .gitignore after they're already in the repo doesn't work and that one possibility is to use git rm --cached file to untrack them.

If I do, will the file no longer be available in the repo for the next person who clones it? Is there a better way to freeze this file in the repo?

解决方案

git rm --cached file will indeed remove the file from the repository, so that in only exists as an untracked file in the current working directory. Future clones will not include the file.

Git doesn't really provide a way to freeze a file so that it cannot be modified. The best you can do is to create a pre-commit hook which resets the file prior to a commit, or preferably aborts the commit until you reset the file yourself.

这篇关于如何冻结存储库中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆