Sometimes you need to operate on a single file in a huge git repository. Tricky part occurs if you don’t want to clone the whole repository content. What you really want to achive is to get desired file, change it and put it back. Luckily there is one simple solution for this challenge.
Magic happens here…
This method implies using git console.
First you need to clone git repository with a special hint –no checkout
git clone --no-checkout <git url>
Whe you execute command your repo will be properly initialized except one thing – you won’t get any files in it. You will get only theirs indexes that are significantly smaller. That’s why the next step you need to perform is to get rid of unstaged files in the repo with the command:
After that your working tree will become completely clear and you will be allowed to start pulling files you want to change with the command:
git checkout origin/master <path to file>
Now the repository folder contains files that you may start editing right away. After editing you need to execute plain and familar sequence of commands.
Adding staged files
git add <path to file>
Commiting staged files
git commit -m <message text>
Dispatching commited files
That’s all. Hope it wll help you to save few hours of restless searching.