我有一个github存储库,我在本地检查过.
environment.local-dev.ts文件中更改了我的环境变量.(它通常指向localhost,但由于我没有安装本地api存储库,我更新了文件以指向我的同事本地api)我搜索了两个选项:
.gitignore.但问题是,我仍然会看到.gitignore,我可能会意外地犯下这些问题..git/info/exclude.我这样做了,但是当我这样做时,我仍然看到了更改过的文件git status我正在研究的Github存储库已经由其他人创建.所以无法改变初始配置.其他人也在同一个存储库上工作,因此无法提交可能会对其他人造成负面影响的更改.
所以,问题是找到一种正在not commit存档的文件tracked by git.有没有办法做到这一点 ?
尝试这个:
git update-index --skip-worktree environment.local-dev.ts
Run Code Online (Sandbox Code Playgroud)
如需进一步阅读,请参阅git update-index 文档和其他相关问题,例如Git - 'assume-unchanged' 和 'skip-worktree' 之间的差异。
编辑:正如@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")
Run Code Online (Sandbox Code Playgroud)
您可以定义一些别名:
[alias]
forget = update-index --assume-unchanged
unforget = update-index --no-assume-unchanged
forgotten = ! git ls-files -v | grep ^[a-z]
Run Code Online (Sandbox Code Playgroud)
更好的方法是使本地忽略配置覆盖文件.