-1

I made change to my files but haven't commit. I accidentally ran a git checkout . which undo all the changes I made.

Is there a way that I can bring back my change?

mana
  • 1,075
  • 1
  • 24
  • 43
  • 4
    Not in Git, no. You asked Git to overwrite your work-tree, and it did that. It did not make a backup first. Your editor(s) and/or IDE and/or OS may have made backups; if so, try using those. – torek Feb 28 '20 at 08:20
  • 1
    To add to what @torek said, if anyone else ever has this problem, you should _immediately_ check the local history of your IDE/text editor, which may not store history forever. – Tim Biegeleisen Feb 28 '20 at 08:24
  • My suggestion: Commit early, commit often, and learn to utilize rebase and amend. There is no reason fret about local commits being imperfect - all can be tidied up and patched together. – user2864740 Feb 28 '20 at 08:30
  • For those who use Visual Studio Code editor, there's a plugin called `Local History` which will keep a copy of changes you made to a file when you saved. I think, this will help to bring back your code if you in this situation. – mana Feb 28 '20 at 08:43
  • Does this answer your question? [Can git undo a checkout of unstaged files](https://stackoverflow.com/questions/2689265/can-git-undo-a-checkout-of-unstaged-files) – phd Feb 28 '20 at 13:06
  • https://stackoverflow.com/search?q=%5Bgit%5D+undo+checkout – phd Feb 28 '20 at 13:06

1 Answers1

2

There is no way to undo that in git.

However if you have the file open in your editor you can undo the changes there. Some editors like Emacs auto save files, so try looking for files with the same file name and a ~ or # extensions.

Refih Can
  • 64
  • 8