我有一个github
存储库,我在本地检查过。
environment.local-dev.ts
文件中的环境变量。 (它通常指向localhost,但由于我没有安装本地api存储库,我更新了文件以指向我的同事本地api)我搜索了两个选项:
.gitignore
中添加文件。但问题是,我仍然会看到.gitignore
,我可能会意外地犯下这个问题。.git/info/exclude
。我这样做了,但是当我git status
我正在处理的Github存储库已经由其他人创建。所以无法改变初始配置。 其他人也在同一个存储库上工作,因此无法提交可能会对其他人产生负面影响的更改。
因此,问题是要找到not commit
tracked by git
文件的方法。有没有办法做到这一点?
答案 0 :(得分:5)
编辑:正如@Philippe skip-worktree
指出的那样比assume-unchanged
更合适。在这个答案中,一切都是一样的,但你只需要切换选项。
.gitignore
和.git/info/exclude
仅用于排除未跟踪的文件。
要忽略对跟踪文件的本地修改,您可以使用git update-index --assume-unchanged FILES...
但是存在忘记需要在文件中提交的修改的风险
要再次显示修改:git update-index --no-assume-unchanged FILES...
。
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
$ git update-index --assume-unchanged file
$ git status
On branch master
nothing to commit, working tree clean
$ git ls-files -v
h file
$ git update-index --no-assume-unchanged file
$ git ls-files -v
H file
$ git status
On branch master
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: file
no changes added to commit (use "git add" and/or "git commit -a")
您可以定义一些别名:
[alias]
forget = update-index --assume-unchanged
unforget = update-index --no-assume-unchanged
forgotten = ! git ls-files -v | grep ^[a-z]
更好的方法是使本地忽略配置覆盖文件。
答案 1 :(得分:2)
试试这个:
git update-index --skip-worktree environment.local-dev.ts
如需进一步阅读,请参阅git update-index documentation和其他相关问题,例如Git - Difference Between 'assume-unchanged' and 'skip-worktree'。
答案 2 :(得分:1)
与其他答案相反,不是assume-unchanged
功能(保留用于检查成本高昂的大文件)应该使用skip-worktree
。