I can remove a file from a git repository with
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.
Basically, try running the following command
git update-index --assume-unchanged <file>
This will stop tracking any local changes to the file
.
To undo the effect of above command, use 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.