I created a repository on github. My initial repository content are as follows:
D:\github\Learn-PyQt>dir Calculate.py Connections.py CurrencyCalculator.py ImprovedSignals.py
All the above files are up-to-date in respect to my remote git repository. What I mean is I have successfully executed git add, git commit, git push on my repository.
Now after the above procedure by mistake I deleted the file Connections.py from my system (localmachine). After deletion I have not yet pushed anything.
Now, as the file is present on my github repository is there any way I can execute a command and update the contents of my local directory mentioned above.
I know that one can delete the current repository and do a git clone but I don’t want to download all the files from my repository. Just the one that is deleted. So, something like git sync currentdirectory.
Simply
You will get back the content of that file as last pushed or last added to the index (minus any local modification you might have done since said last push).
In short,
git checkoutcan be used for a file or a path, not just a full tree like a commit or a tag.If you had made several commits before realizing that your file was deleted, then you would have had to apply one of the solutions of “Restore a deleted file in a Git repo“.
I particularly like, for a directory where some files are missing:
(
git ls-files -dwould show deleted files)