gpt4 book ai didi

git 防止删除被忽略的文件

转载 作者:太空狗 更新时间:2023-10-29 13:45:11 25 4
gpt4 key购买 nike

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

我已将文件放入 .gitignore,但现在每次推送时它都会删除存储库中的文件。

如何防止删除存储库中的文件?谢谢!

最佳答案

使用此标志将您的本地更改标记为未更改,这样 git 将不会跟踪任何更改,包括您的文件删除。

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

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

当您想再次跟踪更改时:

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

--[no-]假定不变

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.

enter image description here

关于git 防止删除被忽略的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34698929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com