Why are my changes gone after a cancelled git commit and how do I recover them?

Andrey Mikhaylov - lolmaus

Here's what I did:

  1. Coded 8 hours worth of changes.
  2. git status displays all my changes.
  3. git add -A
  4. git commit -m "Foo". A pre-commit git hook fires with husky and lint-staged.
  5. I remember that there's a TypeScript typing error I failed to fix, so I press Ctrl+C to cancel.
  6. Absentmindedly, I run git commit -m "Foo" again and immediately cancel.
  7. Changes are gone! The files are reverted, git status is clean, git log and git reflog do not show a new commit.

Why did my changes get reverted? How do I recover them?

step 1 step 2

Andrey Mikhaylov - lolmaus

OK, it was lint-staged to blame. It stashed my changes.

So running git stash apply recovered them!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I "commit" changes in a git submodule?

How do I resolve git saying "Commit your changes or stash them before you can merge"?

I reverted a commit by mistake - how to recover changes

How do I create a cron job that will commit my project changes to git on a weekly basis

Git: why do I have to commit other people's changes

How can I recover a lost commit in Git?

After pull from git remote, Working Copy is flooded with file changes - why? Is it safe to commit them?

How to recover a commit in git

Why does 'git commit' not save my changes?

Git merge overwrites my changes after merge gone wrong

How do I undo the last git commit while preserving changes?

How do I eliminate a commit and it's changes from git history?

How to recover last commit after git hard reset?

How to rollback my DB changes after a commit?

New to git, why I see my changes on develop branch even if I stage them on feature branch?

How do I revert to the beginning of my current commit on git?

How do I apply changes from a specific Git commit somewhere else in the commit tree?

How do I complete a commit in Git Bash after entering the message?

Why did the changes of a git commit disappear after other 2 commits (where I did not change the affected file)?

How can I see the changes in a Git commit?

How do I recover files using git?

How do I recover a dropped stash in Git?

How do I exit my git commit message? I'm NOT in the VIM, I used the " commit -m " command

how do i recover my data

How do I revert my changes to a git submodule?

How do I efficiently rewind and replay my changes in git?

How can I split a commit in two, after I've already committed my changes

How can I see a list of my newly-created files in git without staging them for commit?

How can I recover a staged changes from a deleted git worktree?