从 git 跟踪中删除仅执行文件

remove execute only file from git tracking

我需要使存储库中的文件不可读且不可写:

sudo chmod 101 file1.sh

当你列出它时,它看起来像这样:

$ ls -la file1.sh
---x-----x 1 cardamom cardamom 13 Nov 16 16:52 file1.sh

git add 将不起作用:

error: open("file1.sh"): Permission denied
error: unable to index file file1.sh
fatal: updating files failed

并将其添加到 .gitignore 不会导致它被忽略。
我真的不需要跟踪它,但最好不要在每次输入 git status 时都弹出它。

如何将它添加到存储库或告诉 git 忽略它?

将它添加到 .gitignore 不会对正在跟踪它的修订起作用,因为该文件已经被跟踪.....它会在您删除它(并提交)后对修订起作用.那么,如果你把文件的所有权限都去掉了,你指望git怎么能用呢?它无法读取它。所以...如果您不介意该文件在历史记录中然后消失,您可以将其删除 (git rm --cached the-file),将其添加到 .gitignore,然后提交。对于此修订版 starting 的修订版,该文件将不再显示以供添加。但是,如果您选择签出以前的修订版,那么看到 git 由于文件出现在您的工作树上而表现得很滑稽不要感到惊讶。

How does one either add it to the repo or tell git to ignore it?


--assume-unchaged

在该文件上设置 --assume-unchaged 标志,这样它将停止跟踪对该文件的更改

--[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. 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.