简体   繁体   English

如何在git中提交一次资源,而不是将来更改它?

[英]How to commit a resource once but not future changes to it in git?

Is there a way to commit a file once so it is in the repository but then not commit that file in the future? 有没有一种方法可以提交一个文件,使它位于存储库中,但以后不再提交该文件?

For example, I have a project that I need to commit once so another developer can import the project but I do not want to commit that file again because local path changes mess up his copy of it when he pulls the file down. 例如,我有一个项目,我需要提交一次,以便其他开发人员可以导入该项目,但是我不想再次提交该文件,因为本地路径更改会在他拉下文件时弄乱了他的副本。

I'd like to use SourceTree for working with git but an answer with git commands will work. 我想使用SourceTreegit一起工作,但git命令的答案将起作用。

First commit the initial version of the file. 首先提交文件的初始版本。 Then just run 然后就跑

git update-index --assume-unchanged FILENAME

This will make it so that git will ignore future changes you make to FILENAME . 这样可以使git忽略以后对FILENAME所做的更改。 If in the future, you need to commit something again, run 如果将来需要再次提交某些内容,请运行

git update-index --no-assume-unchanged FILENAME

Note that this only applies to your working copy. 请注意,这仅适用于您的工作副本。 Anyone else who checks out the repository will still have git see their changes unless they also run the command above. 签出存储库的其他任何人仍然可以看到git的更改,除非他们也运行上面的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM