Local History in Rider: undo and redo on steroids

Maarten Balliauw

We’ve all been there. Investigating a bug, making some code changes, then finding that these changes don’t fix the bug. Rinse, repeat, and two hours later we realize that first attempt needed just a little tweak. How can we roll back to it if we did not commit it to Git or Mercurial? How can we roll back any change we made to the code base between source control commits? Undo only goes so far…

In JetBrains Rider, there’s a solution to that: Local History. It’s a real-time, local version control that keeps track of changes we make to our code base.

What is Local History?

When we’re “in the flow”, our project and source code constantly changes. We write, refactor and debug, and when we finish a task, code is committed to a version control system (VCS) like Git or Mercurial.

Unfortunately, commits to the VCS are just snapshots. If we’re lucky, changes in between commits are captured in the undo stack, but that disappears if we close the IDE and reopen it a later time. Undo also does not track external changes, made outside of the IDE. What’s even worse: don’t you hate it when you undo 20 times, then accidentally press the keyboard so you can’t redo anymore?

This is where Rider’s Local History comes in: it keeps track of source code changes and file changes in our project in between VCS commits. Whenever something changes (and is persisted to disk), local history tracks the change and allows us to roll back (or forward). Accidentally deleted a folder of files that weren’t yet committed? Want to get back that class or entire namespace you wrote on the train commute home from work, was dropped a few minutes ago and never committed to source control? Local History!

Local History is enabled by default and keeps track of all every save (or delete), whether explicit (Ctrl+S) or implicit (Rider auto-saves every few seconds). It tracks changes in a solution or project, folders within our solution, files, classes, … As long as the file is text-based, Local History has it covered.

Showing Local History

One place where we can view local history is under the VCS | Local History | Show History menu. It will bring up a diff viewer where we can see a list of changes made to the file we have open. On the left, we can see a description of the changes. On the right, a diff between the current and previous version is shown.

Local History viewer

Just like in a regular diff/merge view, we can restore lines and blocks of code, or roll back to a previous version of the file. Doing so will update the file that is open in the editor, or in the case of e.g. a solution folder, files can be restored.

It’s also possible to label a specific point in time, for example right before we start a massive refactoring effort. Labels can be added using the VCS | Local History | Put label menu, and are shown in the Local History change list as well. Note that labels are solution-wide and apply to all files and folders.

Label local history

What with external changes? Local History tracks those, too. For example, here I dropped the folder Consent outside Rider. Invoking Local History on the parent folder shows us that an external change was detected and we can revert from here if we want to.

External changes can be reverted using Rider

There are a couple of entry points to Local History:

  • The Local History context menu in the Solution Explorer or in the editor (tip: selecting code will show Local History for just the selection)
  • The VCS | Local History menu
  • The VCS operations popup (Ctrl+Alt+Q)

Another entry point is the View | Recent Changes popup (tip: map it to a keyboard shortcut). It shows us a list of recent changes in our solution and lets us quickly open up Local History to view more details.

View recent changes and jump to local history

Cleaning Local History

While having Local History is a real life saver sometimes, its internal database may grow over time. Local History is cleaned when installing a new version of Rider, or when invalidating caches using the File | Invalidate Caches menu.

Keep in mind that Local History really is local. The history is stored locally and not shared with other developers working on the same project. Make sure to keep using proper source control as well!

Download the latest Rider EAP build and experience local history in action! Your feedback is appreciated.

Comments below can no longer be edited.

21 Responses to Local History in Rider: undo and redo on steroids

  1. Sean Feldman says:

    October 26, 2016

    Looks lik
    Is Ctrl-T x3 a IDEA or VS keybinding? VisualStudio doesn’t allow shortcuts with more than twice CTRL- used. Could you please clarify? Thank you.

    • Sean Feldman says:

      October 26, 2016

      Looks like I’ll answer my own question 🙂
      Ctrl-T x3 is VS binding. IDEA key binding would be Ctrl-N x3.
      Thank you Maarten.

      • Maarten Balliauw says:

        October 27, 2016

        Correct 🙂

  2. KP says:

    October 26, 2016

    Like shown in the sample I would say that *.dll.config doesn’t have to be searched (by default), because it is less relevant in my opinion.

    • Maarten Balliauw says:

      October 27, 2016

      In this solution, the .dll.config is explicitly included as a project item, so it makes sense to search in there as well.

  3. Dew Drop - October 27, 2016 (#2354) - Morning Dew says:

    October 27, 2016

    […] Navigate to text in a solution with Go to Text in ReSharper (Maarten Balliauw) […]

  4. Roland Schoofs says:

    December 11, 2016

    How do you skip files like *.Designer.cs?

    • Maarten Balliauw says:

      December 12, 2016

      You can configure this in the options. Under Environment | Search and Navigations, you can specify the files and folders to skip.

  5. Aviran Barda says:

    April 24, 2017

    Hi,
    It seems that for some reason the Resharper Ctrl-T x3 is not searching in my whole solution.
    Instead I think it is searching only in opened files.
    I would like it to search the entire solution. How should I define that?

    • Maarten Balliauw says:

      May 16, 2017

      That should not be the case. Can you try flushing caches? ReSharper | Options | General -> Clear Caches

  6. Alex Maris says:

    May 15, 2017

    I’m running into the same issue as Aviran Barda, the Navigate To Text action is only searching the currently opened files.

    • Maarten Balliauw says:

      May 16, 2017

      Can you try flushing caches? ReSharper | Options | General -> Clear Caches

  7. Ken Bonny says:

    May 18, 2017

    Cool, very powerful feature. One question: does it detect changes when Rider isn’t running?

    Example: I delete a folder while Rider is not running and then I start Rider, will Rider detect the external change correctly or will it be wondering what happened to the folder?

    • Maarten Balliauw says:

      May 18, 2017

      It will detect the changes between two runs of Rider as external change. So this folder delete will be seen as a folder delete in local history.

      • Ken Bonny says:

        May 18, 2017

        Very impressive. Keep up the good work.

  8. Dew Drop - May 18, 2017 (#2482) - Morning Dew says:

    May 18, 2017

    […] Local History in Rider: undo and redo on steroids (Maarten Balliauw) […]

  9. Dude says:

    May 18, 2017

    When will Nitra be released? Is Nemerle going to be the Kotlin/Scala of .NET world?

  10. CakePHP 3.4.9 erschienen & IBM veröffentlicht Microservice Builder says:

    June 26, 2017

    […] Ein kleiner Fehler im Bugfix kann sich zum großen Ärgernis auswachsen: Wer den Fehler im Fehler nicht sieht, glaubt schnell, auf der falschen Spur zu sein. Und schon zieht sich die Suche nach einer Lösung endlos in die Länge. Wenn man dann endlich darauf kommt, dass Lösungsansatz Nr. 1 (von inzwischen zehn oder mehr) schon fast richtig war, muss man halt einfach noch mal von vorne anfangen, oder? Nicht mit Rider. In der .NET IDE von JetBrains steht Entwicklern eine lokale Versionskontrolle zur Verfügung. Damit lassen sich nicht nur die „großen“ Änderungen wieder zurücksetzen, die man bereits auf Git geladen hat, sondern Rider erlaubt auch einen Rollback auf lokaler Ebene. Jede auf der Festplatte gespeicherte Änderung ist wiederherstellbar. Die Details dieses lokalen VCS in Rider erklärt Maarten Balliauw im JetBrains-Blog. […]

  11. Lutz Fritsche says:

    December 4, 2017

    Where is the usual “whole word” option?

    • Maarten Balliauw says:

      December 4, 2017

      You can add quotes around the search term.

  12. Jer says:

    June 22, 2020

    This just helped prevent my absolute devastation from accidentally deleting a directory full of code. Phew.

Subscribe

Subscribe to .NET Tools updates