2

I moved the content of an old file to a new one, made a few changes and committed everything.

Unfortunately I didn't commit directly after "renaming" the file, so git didn' t track that and the now history is lost.

Is there any way to get it back?

Michael
  • 538
  • 1
  • 7
  • 16
  • 1
    You copied something from file A to file B, then you committed everything. So what is lost? – Huy Vo Mar 23 '18 at 02:10
  • 1
    Possible duplicate of [How does git detect similar files, for its rename detection?](https://stackoverflow.com/questions/7938582/how-does-git-detect-similar-files-for-its-rename-detection) – Tim Biegeleisen Mar 23 '18 at 02:14
  • Long story short, Git can't always track renaming of files, so if you absolutely need to preserve history, then _don't_ rename your files. Follow the duplicate link for a detailed explanation of how Git works here. – Tim Biegeleisen Mar 23 '18 at 02:15

1 Answers1

1

History is not lost, it is accessible by old path:

git log -- OLD_PATH

git may or may not detect the move, but in the commit you should see that line added to the new file and removed from the old one, so it is discoverable if somebody searches for its origin.

max630
  • 8,762
  • 3
  • 30
  • 55