簡體   English   中英

忽略 git 中修改(但未提交)的文件?

[英]Ignore modified (but not committed) files in git?

我可以告訴 git 忽略已修改(刪除)但不應提交的文件嗎?

情況是我在 repo 中有一個子目錄,其中包含我根本不感興趣的東西,所以我刪除了它以防止它出現在自動完成等(在 IDE 中)。

但是現在,如果我將該文件夾添加到 .gitignore,則根本沒有任何變化,所有內容都顯示為 git 狀態已刪除。

有沒有辦法讓 git 忽略它?

(或者,當我使用 git-svn 時,我可以將更改提交到本地 git 並確保它們不會傳遞到 svn 存儲庫嗎?)

查看git-update-index 手冊頁和 --assume-unchanged 位和相關的。

當我遇到你的問題時,我會這樣做

git update-index --assume-unchanged dir-im-removing/

或特定文件

git update-index --assume-unchanged config/database.yml

更新更好的選擇是git update-index --skip-worktree不會在硬重置或拉取的新更改時丟失。

請參閱http://schacon.github.com/git/git-update-index.html的手冊頁

並在http://fallengamer.livejournal.com/93321.html進行比較

使用此代碼

git update-index --assume-unchanged file-name

我通常做的是

git stash

git whatever-else

git stash apply

git stash clear

跟蹤的文件不能被忽略,因此您必須先將它們從索引中刪除。 添加一個.gitignore忽略您不想要的目錄,然后刪除它們,並使用git rm --cached刪除任何落后者。

在我的情況下有效:

git restore --staged filename

示例: git restore --staged index.js

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM