[英]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.