0

I want to revert a public repo I recently cloned back to a previous version of itself from a year ago. I don't want to do a hard revert.

I have already tried this:

cd MyRepo
git revert --no-commit dc3b4359.. 

But I got this error:

error: could not revert dc3b4359...
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'

I am a novice at this; what code could be used to do this safely? Thanks in advance.

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
Kat
  • 21
  • 3
  • What do you mean by a "hard revert"? What should happen to the files in the repository, what should happen to the history? – choroba Jun 15 '19 at 23:32
  • This is not an error. This is a [conflict](https://stackoverflow.com/questions/161813/how-to-resolve-merge-conflicts-in-git). But as a sidenote, reverting a ton of commits like that seems an unnecessary burden. Why did you rule out a hard reset (I guess you meant hard reset since hard revert is meaningless) – Romain Valeri Jun 15 '19 at 23:32
  • You tried to revert a single commit. Git does this by appending change, which is the opposite of dc3b4359. That change is conflicting with other commits that happened after. – Stijn Haezebrouck Jun 15 '19 at 23:32
  • @StijnHaezebrouck The general point about the behaviour of `revert` is correct but OP's command is not reverting a *single* commit. It reverts a whole range (mind the double dots). – Romain Valeri Jun 15 '19 at 23:34
  • @RomainValeri you are correct of course, overlooked those – Stijn Haezebrouck Jun 15 '19 at 23:37

1 Answers1

0

(EDITED) (thanks @torek)

The most crude way would be:

cd MyRepo
git rm -r .
git checkout dc3b4359 -- .
git add .
git commit -m "Going back in time"
git push origin master

Original answer:

cd MyRepo
rm -rf * # if you have files starting with '.', delete them too.
git checkout dc3b4359 -- .
git add .
git commit -m "Going back in time"
root
  • 5,528
  • 1
  • 7
  • 15
  • 1
    Sometimes better to use `git rm` so that you don't disturb untracked files, but yes, that method will work in the local repo; OP will then need to `git push` the resulting commit. – torek Jun 16 '19 at 00:31