Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit deleted file changes in Intellj IDEA?

I have some file sample_file.doc which is visible in my IntelliJ IDEA.

If I delete sample_file.doc file from the local folder it disappear from IntelliJ IDEA, not allowing me to commit the deleted file changes.

I want to commit the deletion so that the deleted file change appear in Git repository.

Please advise how to commit deleted files in IntellJ IDEA?

like image 626
lemdev Avatar asked Dec 18 '22 18:12

lemdev


2 Answers

Recent updates to IntelliJ (2019.3) have broken its ability to easily commit deletions. Presently (2019.3), when you only delete a file, IntelliJ disables the commit option.

To trick IntelliJ, just make a trivial change to any other file, and then open the commit dialog. Unselect the changed file, leaving only the deleted file selected, and then commit. When finished, undo the change to the file you didn't delete.

Or just give up and do it from the command line (which is actually easier, but doesn't afford you some of the nicer dialog options, such as commit message history, etc.).

like image 59
Sharky Avatar answered Jan 03 '23 18:01

Sharky


In IntelliJ IDEA open View → Tool Windows → Version Control, or just press (9 on macOS) or (Alt9 on Windows).

In Version Control panel make sure the Local Changes tab is selected:

enter image description here

  • Grey color means deleted file
  • Blue color means amended file
  • Green color means a new file

There are other pretty handy VSC features that come out of the box with IDEA, for instance:

  • (K on macOS) or (CtrlK on Windows) to Commit your local changes
    • it the same dialog select file and press (D on macOS) or (CtrlD on Windows) to see the difference
  • (shiftK on macOS) or (CtrlShiftK on Windows) to Push your commits. There is also an option on the right side of Push button to Force Push.
  • meanwhile you can always press (optionZ on macOS) or (CtrlAltZ on Windows) to open Revert Changes window where checking diffs works as well

But you can also run a Terminal window right in IDEA by pressing

  • optionF12 on macOS
  • AltF12 on Windows

and use git status command to see what is going on:

enter image description here

like image 39
DimaSan Avatar answered Jan 03 '23 20:01

DimaSan