如何停止跟踪文件并将其当前状态保持在 Git?
How do I stop tracking a file and keep its current state in Git?
我的 python 程序有一个配置文件,用户必须在其中插入 API 密钥。
我正在使用 Git 跟踪文件,我提交的文件只是一个模板表单。
我自己需要用我的私人 API 密钥使用该文件,所以我如何告诉 Git 模板版本是 "final" 版本并且不跟踪任何进一步的更改?
您可以将文件标记为 "skip-worktree",从那时起,对该文件的更改将在 diff 和提交时被忽略:
git update-index --skip-worktree filename
当合并或拉取影响文件时,您将得到一个错误并且必须重置标志(这样做是为了防止错误)。
见https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html
I need to use the file myself with my private API key so how do I tell Git that the template version is the "final" version and to not track any further changes?
将文件添加到您的存储库后,将其添加到 .gitignore
将不起作用,因为它已被 git 跟踪。
您将需要使用 assume-unchanged
标志
https://git-scm.com/docs/git-update-index
git update-index --assume-unchanged <path>
如果您需要打印出标有 --assume-unchanged
标志的文件列表:
git ls-files -v|grep '^h'
--[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.
我的 python 程序有一个配置文件,用户必须在其中插入 API 密钥。
我正在使用 Git 跟踪文件,我提交的文件只是一个模板表单。
我自己需要用我的私人 API 密钥使用该文件,所以我如何告诉 Git 模板版本是 "final" 版本并且不跟踪任何进一步的更改?
您可以将文件标记为 "skip-worktree",从那时起,对该文件的更改将在 diff 和提交时被忽略:
git update-index --skip-worktree filename
当合并或拉取影响文件时,您将得到一个错误并且必须重置标志(这样做是为了防止错误)。
见https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html
I need to use the file myself with my private API key so how do I tell Git that the template version is the "final" version and to not track any further changes?
将文件添加到您的存储库后,将其添加到 .gitignore
将不起作用,因为它已被 git 跟踪。
您将需要使用 assume-unchanged
标志
https://git-scm.com/docs/git-update-index
git update-index --assume-unchanged <path>
如果您需要打印出标有 --assume-unchanged
标志的文件列表:
git ls-files -v|grep '^h'
--[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.