简体   繁体   English

git阻止删除加载的文件

[英]git prevent deleting ingored files

I need to have two different version of same file - one on local machine and one on the server (repo). 我需要有两个不同版本的同一个文件 - 一个在本地机器上,一个在服务器上(repo)。

I have put file to .gitignore , but now during each push it will delete file on the repo. 我已将文件放到.gitignore ,但现在在每次推送期间它将删除repo上的文件。

What to do to prevent deleting file on the repo? 如何防止在repo上删除文件? Thank you! 谢谢!

Use this flag to mark your local changes as unchanged so git will not track any changes including your file delete. 使用此标志将本地更改标记为未更改,以便git不会跟踪任何更改,包括文件删除。

To temporarily ignore changes in a certain file, run: 要暂时忽略某个文件中的更改,请运行:

git update-index --assume-unchanged <file>

When you want to track changes again: 如果要再次跟踪更改:

git update-index --no-assume-unchanged <file>

--[no-]assume-unchanged - [无糖]假设 - 不变

When this flag is specified, the object names recorded for the paths are not updated. 指定此标志时,不会更新为路径记录的对象名称。
Instead, this option sets/unsets the "assume unchanged" bit for the paths. 相反,此选项设置/取消设置路径的“假定未更改”位。

When the "assume unchanged" bit is on, the user promises not to change the file and allows Git to assume that the working tree file matches what is recorded in the index. 当“假设未更改”位打开时,用户承诺不更改文件并允许Git假定工作树文件与索引中记录的文件匹配。 If you want to change the working tree file, you need to unset the bit to tell Git. 如果要更改工作树文件,则需要取消设置该位以告知Git。 This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (eg cifs). 当在具有非常慢的lstat(2)系统调用(例如cifs)的文件系统上处理大项目时,这有时是有用的。

Git will fail (gracefully) in case it needs to modify this file in the index eg when merging in a commit; 如果需要在索引中修改此文件,例如在提交中合并时,Git将失败(优雅); thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually. 因此,如果上游更改了假定未跟踪文件,则需要手动处理该情况。

在此输入图像描述

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

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