git阻止删除加载的文件

我需要有两个不同版本的同一个文件 – 一个在本地机器上,一个在服务器上(repo).

我已将文件放到.gitignore,但现在在每次推送期间它将删除repo上的文件.

如何防止在repo上删除文件?
谢谢!

最佳答案 使用此标志将本地更改标记为未更改,以便git不会跟踪任何更改,包括文件删除.

要暂时忽略某个文件中的更改,请运行:

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

如果要再次跟踪更改:

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

– [无糖]假设 – 不变

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. If you want to change the working tree file, you need to unset the bit to tell Git. This is sometimes helpful when working with a big project on a filesystem that has very slow lstat(2) system call (e.g. cifs).

Git will fail (gracefully) in case it needs to modify this file in the index e.g. when merging in a commit; thus, in case the assumed-untracked file is changed upstream, you will need to handle the situation manually.

《git阻止删除加载的文件》

点赞