在不更改 gitignore 项目的情况下忽略本地的一些文件

ignore some files in locally without change gitignore project

我不是 GIT 的专家,我在 git 中只使用 git addgit commit -m 和 bla bla(基本), 我已经从克隆项目中获得了一个文件 .gitignore,并且它已经由团队设置。但是对于 运行 项目,我有另一种方法可以在 Makefile 中添加一些语法,因为我不能使用该项目的 Makefile 默认值,我有自己的设置。

所以我在这里更改了 Makefile 的文件,但每次我想 git status 那个 Makefile 状态是 unstaged for commit,所以我必须手动 git checkout -- Makefile,它将像以前一样恢复该文件,并且不会添加到 git,因为我的主要问题是:

我想在本地忽略该文件,如何在命令行中执行此操作?

Git 无法忽略对跟踪文件的更改。

来自git update-index documentation

Users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked. This does not work as expected, since Git may still check working tree files against the index when performing certain operations. In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended.

您最好创建一个您在本地忽略(在 .git/info/exclude 中)的文件(例如,Makefile.local),其中包含如下内容:

# Variable overrides here.

-include Makefile

# Other overrides here.

然后 运行 make -f Makefile.local。如果您只想在变量中进行更改(例如,您想为程序使用不同的位置),则只需在命令行中添加变量:make CC=clang.