6

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.

BJ Myers
  • 6,617
  • 6
  • 34
  • 50
ThanksBro
  • 911
  • 1
  • 7
  • 20
  • Git is version control system by itself. Why do you need refactoring logs to be stored? – madhead Feb 08 '13 at 10:01
  • So that when I check the history of the file I can see all the changes. When I do git mv that is seen, but when intelliJ refactors it it is not seen – ThanksBro Feb 08 '13 at 11:01

2 Answers2

3

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.

Community
  • 1
  • 1
CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 3
    In the bug report it looks like it works when refactoring in terminal, and it doesnt work when refactoring in IntelliJ. Thanks, I will continue on Youtrack – ThanksBro Feb 09 '13 at 09:19
2

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
machinery
  • 3,793
  • 4
  • 41
  • 52