Recently I had to deal with a strange issue of IntelliJ when I've trying to move my Scala class to other package. The class looked like in the following snippet:
case class FirstCaseClass(....) case class SecondCaseClass(....) case class ThirdCaseClass(...)
Unfortunately, after moving the class in IntelliJ, instead of receiving 3 case classes in a single file, the 3 separate files were created. In such case the original file was marked as deleted and 3 new files were considered as "to add", similarly to the following snippet:
On branch master Changes to be committed: (use "git reset HEAD..." to unstage) deleted: file1.txt Untracked files: (use "git add ..." to include in what will be committed) file1_bis.txt
The first try to restore the file state to the state before changes was the use git checkout ${file_name} command. But it didn't work because the file was removed with git rm ${file_name} command:
bartosz:~/workspace/git_tests/undo_file_delete$ git checkout file1.txt error: pathspec 'file1.txt' did not match any file(s) known to git.
To undo the file delete in Git we should begin by restoring the file status in the index:
bartosz:~/workspace/git_tests/undo_file_delete$ git reset -- file1.txt Unstaged changes after reset: D file1.txt
Only at the end we can use the famous checkout command:
bartosz:~/workspace/git_tests/undo_file_delete$ git checkout file1.txt bartosz:~/workspace/git_tests/undo_file_delete$ git status On branch master Untracked files: (use "git add..." to include in what will be committed) file1_bis.txt nothing added to commit but untracked files present (use "git add" to track)