Search code examples
gitfile-rename

File Rename detection in git when we relocate


Lets assume a scenario that i have a remote, a developer1 and a developer2. Developer1 pushes his project in the remote. Developer2 clones the project from the remote,and he renames a file, and puts it in another folder.Then he pushes the project to the remote. Then developer1 fetches the project from the remote.

In that case, will the renaming mechanism of git recognize that my renamed file is on that other folder?


Solution

  • Git has a very good mechanism for detecting file renames/moves. If the content of the file isn't changed to much (I think 90% of the content need to be the same) git will detect this as a move/rename. This will be shown like this in the commit message:

    file.txt -> folder/file.txt
    

    If git didn't detect the file move (because to much of the file was changed) you can tell that to git by doing:

    git mv file.txt folder/file.txt
    

    This way you can be sure that moving the file is detected.

    Either way each operation of developer2 will be done to your local copy of the code, including renames, when you are pulling in the changes.