I have made some changes in ignored files, so I want to rollback it by pull it from remote repository. How can I do it without reinstall repository?
re-install the repository is not the correct term. You don't install a repository. You either clone it or fetch/pull changes from its remote(s).
Rollback changes is a thing, but here you mean to say that you modified an ignored file and now you'd like to revert it to its previous state.
git checkout -- <yourfile>
will restore it to its state prior the changes, as if it was taken from the repository. Remember that git is ignoring only those files that are not currently tracked. So, if it is on the remote repository, then it was tracked. If you pulled that file from the remote, even if it is added to .gitignore
, changes will show in git status
(you can test this).
However, if git rm --cached
was run for that ignored file, then it was removed from git AND a new commit should've been created with the deletion. If so, then the file is not cloned from the remote repository.
In the end: you might still have a copy of that unchanged file locally, and have kept it through pull/fetch operations. If you'll try to clone the repository and checkout that branch you are working on, the ignored files should not be there. Otherwise, git checkout -- <file>
should work, since the file is actively tracked.
How to get back that file then
You'll have to track down the last commit in which the file was present. Let's say it is 12345abc
. Now, go ahead and do git checkout 12345abc <file>
. Note that is forcingly adding and tracking that file again and you'll have to be careful about what you commit next.
Usually, you ignore autogenerated files that can be generated by your local environment, and/or are strongly dependent on your local environment. Chances are you can revert changes outside git, if this strategy was followed.