简体   繁体   English

如何从git存储库中删除文件,而不在克隆的存储库中删除它

[英]How to remove a file from a git repository, without deleting it in cloned repositories

I can remove a file from a git repository with 我可以从git存储库中删除文件

git rm --cached <file>

But when I pull these changes in a cloned directory, this file will be deleted there. 但是当我在克隆目录中提取这些更改时,此文件将被删除。

Is it possible avoid this without saving this file in all clones and restore it after pulling? 是否可以避免这种情况而不在所有克隆中保存此文件并在拉出后恢复它?

I think you are looking for assume-unchanged flag. 我认为你正在寻找assume-unchanged旗帜。

Basically, try running the following command 基本上,请尝试运行以下命令

git update-index --assume-unchanged <file>

This will stop tracking any local changes to the file . 这将停止跟踪file任何本地更改。

To undo the effect of above command, use git update-index --no-assume-unchanged 要撤消上述命令的效果,请使用git update-index --no-assume-unchanged

The idea of a clone of a repository is that it is meant to be the same, so pulling will always make the two repos the same. 克隆存储库的想法是它应该是相同的,因此拉动将始终使两个存储库相同。 If you want to have two different sets of files you could create a new branch with the deleted file gone using 如果您想拥有两组不同的文件,可以使用已删除的文件创建一个新分支

git checkout -b <branch_name>

and then commit the deleted file there. 然后在那里提交已删除的文件。

If you really don't want to do this you could always pull the changes and then easily get the file back by using 如果您真的不想这样做,您可以随时提取更改,然后通过使用轻松获取文件

git checkout HEAD^ -- <file>

Which checks out the file from the commit before last. 其中最后一次从提交中检出文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Git 存储库中删除文件而不从本地文件系统中删除它 - Remove a file from a Git repository without deleting it from the local filesystem 如何从目录中删除git存储库而不删除其中的任何内容? - How to remove a git repository from a directory without deleting anything from it? Git:如何从索引中删除文件而不删除任何存储库中的文件 - Git: How to remove file from index without deleting files from any repository 如何从git add index中删除文件而不从任何存储库本地删除文件 - How to remove file from git add index without locally deleting files from any repository Git - 如何从存储库 (devops) 中删除文件而不在本地克隆它 - Git - How to remove a file from repository (devops) without cloning it locally 如何在本地和远程存储库中从Git中的版本删除文件而不删除它们 - How to remove files from versioning in Git without deleting them, both locally AND ON A REMOTE repository 如何在不更新从中克隆的本地存储库的情况下设置 git 存储库的远程 url? - How to set a git repository's remote url without updating the local repository it's cloned from? 从Git历史记录中删除文件而不删除该文件 - Remove a file from Git history without deleting the file 如何让git从存储库中删除文件 - How to have git remove file from repository Eclipse Git插件 - 从repo中删除文件而不删除本地 - Eclipse Git plugin - remove file from repo without deleting local
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM