How do I recover the history of an incorrectly moved file in git?

I moved a file to my repository and git didn't detect it as a move. He discovered this as deleting and adding a file. I made this change and then did many more. After that, I realized that I don't see the history of the moved file.

I found the cause of my error and now I want to find how I can fix it.

Is there a way to recover the history of a file?

This View git history of moved files does not solve my problem because I am not moving the file correctly. All history is lost.

+3


source to share


1 answer


First, I think you are misunderstanding the renaming to git

. The git

file will never be "misplaced" because it git

tracks the content, not the files and filenames. The creator git

, Linus Torvalds, talks about these renames:

git doesn't really even care about all the "rename detection" internally, and any commits you make with renames are completely independent of the heuristics we use to display renames. 1

So, what might actually be what git log --follow

doesn't work for you because it --follow

only checks for renaming files, which are 50% similar by default. However, your file may only be 20% or 30% similar to the renamed version. Try using it --find-renames=<n>

with different values ​​below 50% and see if that fixes the problem:



git log --follow --find-renames=35% path/to/your/renamed/file

      

0


source







All Articles