-2

I want to revert the commit of other and also I am not the contributor to that library I am simply an assistant which have to do some changes in the git repository. Till here I clone a repository and the file which I have to revert I found that commit using git log and found out that commit and when I do git revert commit_id I get this error.

error: your local changes would be overwritten by revert. hint: commit your changes or stash them to proceed. fatal: revert failed

My question is what should be the step which I have to take to revert the commit of others by keeping in mind that I am not a contributor or done anything for that repository?

isherwood
  • 58,414
  • 16
  • 114
  • 157
Ab Danyia
  • 69
  • 7
  • You need a clean working tree. `git stash` is a way to keep them aside. `git reset --hard` is to get rid of them (permanently, beware). – Romain Valeri Oct 27 '21 at 16:04
  • Thank you for your answer, after doing **git stash** it worked fine, now I did revert the file but it is shown in my local machine but not on the github main repository? – Ab Danyia Oct 27 '21 at 16:22

2 Answers2

1

That error isn't about permissions. It's about local changes that Git is protecting from accidental destruction. Deal with those first, with a commit, stash, reset, etc. When your stage is clear you'll be able to revert. Whether you can push is another matter, depending on permissions.

isherwood
  • 58,414
  • 16
  • 114
  • 157
  • I am new to git. as you mentioned deal with a commit,stash,reset etc. what are these and why do I have to do it before reverting a commit? Thank you – Ab Danyia Oct 27 '21 at 16:04
  • 1
    Sorry, but I won't be writing an entire Git primer. Please do your own study of Git basics. The short answer is that, if you ask Git to do something that modifies files with uncommitted changes, it warns you. – isherwood Oct 27 '21 at 16:07
0

Try doing a git commit or git stash. As in the previous answer your stage must have something that prevents the commit.