0

I accidentally selected Git Add on an entire project tree (in IntelliJ Idea editor) rather than Git Commit which added 4000+ files I didn't want to Add, then newbie error of immediately doing Git Revert afterwards to try and reverse my mistake. Obviously it has now erased all my code changes since the last commit. Is there any way to undo both mistakes and get my work back?

I haven't done a commit or push on the latest work that I lost. Thanks

Alex Kerr
  • 956
  • 15
  • 44
  • Can you describe each command you made and the sequence that you execute them? These informations will be helpful to understand the scenario that you are now. Also, the Intellij IDEA save a file history independent from Git, so maybe that can help you to, at least, save part of your work. – Dherik Feb 03 '20 at 12:26
  • It looks like the "Revert" command in IntelliJ Idea does something very different from the `git revert` command in the shell. I tried to find documentation on what exactly "Revert" does in Idea, but couldn't find it immediately. I _suspect_ that it discards all local changes. Depending on how exactly it does this, your local changes may be lost. – Sven Marnach Feb 03 '20 at 12:49
  • 1
    As a side note, the fact that running `git add` adds thousands of files you don't want to add indicates that you may want to update your `.gitignore` to ignore the files you don't want to add. The `git status` command should show `working tree clean` whenever there are no local changes you want to commit to version control. – Sven Marnach Feb 03 '20 at 12:52
  • You can use the local history to restore the state of your changes before "git revert" (right-click the root of your project in Project View and select "Local History | Show History"). – yole Feb 03 '20 at 13:57
  • @yole thanks yes that seems to be the solution! – Alex Kerr Feb 03 '20 at 14:01

1 Answers1

0

Thanks for answers above, appreciated. Yep as Sven suggested, Revert in IntelliJ does wipe all your local code changes. Turns out the solution is to use Local History in IntelliJ, but on the entire project (right click on top folder in project) then the Revert I did had itself a revert button, right clicking on that gives a Revert option that does an IntelliJ version of reverting the revert and then everything was restored, including directory renaming I'd done.

Alex Kerr
  • 956
  • 15
  • 44