Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep the change log in git files when refactoring in IntelliJ?

When I refactor the class in IntelliJ the git looses the track of old log of the file? Is there a way to refactor the file so that it keeps the log, or am I missing something?

I am checking the log of the file in the SourceTree, but I imagine it is the same for everything.

like image 201
ThanksBro Avatar asked Feb 08 '13 09:02

ThanksBro


People also ask

How do I see Git changes in IntelliJ?

IntelliJ IDEA allows you to review all changes made to the project sources that match the specified filters. For distributed version control systems, such as Git and Mercurial, you can view project history in the Log tab of the Version Control tool window Alt+9 (see Investigate changes in Git repository).

How do I view Git log in IntelliJ?

IntelliJ IDEA lets you review the state of your project at a selected revision. Open the Git tool window Alt+9 and switch to the Log tab. Select a commit and choose Show Repository at Revision from the context menu.


2 Answers

Move/Rename is handled automatically by Git and log should be kept if git detected that it was actually a move. It doesn't matter whether you rename from IDEA, terminal or file manager.

See also Why does git not "track" renames? and comments in the related bug report.

like image 137
CrazyCoder Avatar answered Oct 15 '22 20:10

CrazyCoder


This approach, although probably not what you would like to hear, helped git detect renames (and ultimately understand the real file history) during a pretty big repackaging that I was doing (renaming package com.something to com.somethingelse with ~300 files inside it):

  1. Do the renaming only outside of IntelliJ using "git mv" e.g. "git mv MyProject\src\main\java\com\something MyProject\src\main\java\com\somethingelse"
  2. Commit
  3. Do the repackaging changes in the source files using a regular IntelliJ text-replace - Edit > Find > Replace in path and replace all occurrences of com.something with com.somethingelse.
  4. Commit
like image 26
machinery Avatar answered Oct 15 '22 20:10

machinery