[英]How to ignore files locally without adding it in .gitignore
我有一個github
存儲庫,我在本地檢查。
environment.local-dev.ts
文件中更改了我的環境變量。 (它通常指向localhost,但由於我沒有安裝本地api存儲庫,我更新了文件以指向我的同事本地api) 我搜索了兩個選項:
.gitignore
添加文件。 但問題是,我仍然會看到.gitignore
,我可能會意外地犯下這個問題。 .git/info/exclude
。 我這樣做了,但是當我執行git status
時,我仍然看到更改的文件 我正在研究的Github存儲庫已經由其他人創建。 所以無法改變初始配置。 其他人也在同一個存儲庫上工作,因此無法提交可能會對其他人產生負面影響的更改。
所以,問題是找到一種not commit
tracked by git
文件的方法。 有沒有辦法做到這一點 ?
編輯 :正如@Philippe指出的那樣, skip-worktree
比assume-unchanged
skip-worktree
合適。 在這個答案中,一切都是一樣的,但你只需切換選項。
.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]
更好的方法是使本地忽略配置覆蓋文件。
嘗試這個:
git update-index --skip-worktree environment.local-dev.ts
有關進一步閱讀,請參閱git update-index文檔和其他相關問題,例如Git - “假設未更改”和“跳過工作樹”之間的差異 。
與其他答案相反,不是assume-unchanged
功能(保留用於檢查成本高昂的大文件),您應該使用但skip-worktree
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.