![](/img/trans.png)
[英]Remove a file from a Git repository without deleting it from the local filesystem
[英]How to remove a file from a git repository, without deleting it in cloned repositories
我可以從git存儲庫中刪除文件
git rm --cached <file>
但是當我在克隆目錄中提取這些更改時,此文件將被刪除。
是否可以避免這種情況而不在所有克隆中保存此文件並在拉出后恢復它?
我認為你正在尋找assume-unchanged
旗幟。
基本上,請嘗試運行以下命令
git update-index --assume-unchanged <file>
這將停止跟蹤file
任何本地更改。
要撤消上述命令的效果,請使用git update-index --no-assume-unchanged
克隆存儲庫的想法是它應該是相同的,因此拉動將始終使兩個存儲庫相同。 如果您想擁有兩組不同的文件,可以使用已刪除的文件創建一個新分支
git checkout -b <branch_name>
然后在那里提交已刪除的文件。
如果您真的不想這樣做,您可以隨時提取更改,然后通過使用輕松獲取文件
git checkout HEAD^ -- <file>
其中最后一次從提交中檢出文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.