question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using Undo On Local Commits Can Lead to Data Loss

See original GitHub issue

Description

Data loss can happen if you use the ‘undo’ functionality on a reverted local commit. Noticed this when playing with #5873.

Version

  • GitHub Desktop: 1.4.2
  • Operating system: macOS 10.13.6

Steps to Reproduce

  1. Make a change to a file.
  2. Make a commit for this change, but do not push, so that it stays local.
  3. Go to History tab, right-click on the local commit, ‘Revert This Commit’. There are now 2 local commits that haven’t been pushed.
  4. Go to the Changes tab. Undo both commits.
  5. View file on disk, the change made in step 1 should be gone.

Expected Behavior

The change from step 1 should still be in the file. This is the behavior that happens if you simply skipped step 3 and used undo on the commit from step 2.

Actual Behavior

When you undo the revert commit, the Changes tab shows the change from step 1 for that file, as if it’s not committed by the commit from step 2, and the change is available to commit. I think this is the crux of the issue, as this is when things diverge between GitHub Desktop and the file on disk. If you only undo the revert commit, then view the file on disk, you’ll see that it’s back to the HEAD version, without the change from the commit in step 2, but the change is visible under Changes. So the Changes tab at this point is not reflecting the file on disk. Undoing the original commit removes the changes from the Changes tab, so now it reflects what’s on disk, and now there’s data loss, as the change from step 1 is lost.

Additional Information

Logs

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:20 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
megaslavcommented, Apr 29, 2020

This issue is still going on! I just lost hours of work because of this, worse part is I didn’t even notice until I read this post. I just assumed GitHub Desktop was simply not seeing my changes, so I decided to google for it.

This is a very very bad bug. I don’t understand how can you have this software out there?

4reactions
stevewardcommented, Jan 8, 2021

Apologies for not providing an update about this issue sooner. We’re exploring ways to make it easier to recover from these types of situations, but for the time being I’d like to provide some more context about what’s happening and how to recover from it.

Here’s the equivalent from the command line of what GitHub Desktop is doing when you follow the revert -> undo -> undo pattern:

git revert <SHA_of_most_recent_commit> git reset —mixed HEAD~1 git reset —mixed HEAD~1

The double-reset is what is causing the changes to be lost from your working directory. Thankfully Git makes it really hard to lose work that has been previously committed to your repository. Since this work was previously committed it can be recovered by running the git reflog command from the command line. After running that command you should see the specific SHA and the commit message of your commit that was lost during the undo process. The commit can then be recovered by creating a new branch off of the SHA found in the reflog. Here is the specific command you will need to run from the command line:

git checkout -b recovery <SHA>

The recovery branch can then be merged back into your main branch in Github Desktop.

If you have any questions about this process please let me know and I’d be happy to help further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I undo the local commits in Git? [duplicate]
Firstly, use the command git log to see all the commits. git log. Copy the commit ID which you want to remove and...
Read more >
2.4 Git Basics - Undoing Things
This command takes your staging area and uses it for the commit. ... with an --amend commit can be recovered (see Data Recovery...
Read more >
Undo possibilities in Git - GitLab Docs
Undo staged local changes. If you added a file to staging, you can undo it. Confirm that the file is staged (that you...
Read more >
4. Undoing and Editing Commits - Git Pocket Guide [Book]
Changing already published commits is awkward, of course, since it would cause others to lose history they already have; Git will warn people...
Read more >
On undoing, fixing, or removing commits in git - Seth Robertson
Any changes which are removed here cannot be restored later. This will not delete untracked or ignored files. Those can be deleted with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found