-2

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?

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44
  • Does this answer your question? [How can I reset or revert a file to a specific revision?](https://stackoverflow.com/questions/215718/how-can-i-reset-or-revert-a-file-to-a-specific-revision) – Malice Jul 22 '20 at 10:30
  • no cause files are ignored – sotoro viridla Jul 22 '20 at 10:40
  • Sorry, I misunderstood your question. As I understand it, if a file is ignored then any changes to it aren't going to be tracked by Git so there is nothing to rollback to. – Malice Jul 22 '20 at 11:09
  • but on remote repository ignored files have no changes – sotoro viridla Jul 22 '20 at 11:18
  • If you can see the files in the remote repository then, unless I'm missing something, they aren't being ignored and you should be able to find the answer you need in the question I linked earlier. – Malice Jul 22 '20 at 11:38

1 Answers1

0

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.

Daemon Painter
  • 3,208
  • 3
  • 29
  • 44