Reputation: 49587
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
.
Upvotes: 1
Views: 6234
Reputation: 1328292
Simply
git checkout -- Connections.py
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 checkout
can 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 -d | xargs git checkout --
(git ls-files -d
would show deleted files)
Upvotes: 2