How can I control the renaming threshold when writing files in git?

I am trying to post sequential snapshots of a specific project in git stories. I do this by populating the repository directory with the contents of each snapshot, and then running

git add -A . git commit -m 'Version X' 

This is the method recommended in this answer . However, I see that commit recognizes file renaming only when 100% of the contents of the file remains unchanged. Is there a way to influence the definition of git commit renaming to find renames where the contents of the file have changed a bit? I see that git merge and git diff have different options for controlling the rename threshold, but these options do not exist for git commit .

Things I tried:

  • Search for renamed files using the homebrew script and commit with the source files renamed to their new locations before transferring the new contents of the file. However, this introduces an artificial commit and seems inelegant as it does not use the git rename functionality.
  • Create a separate branch for each snapshot, and then merge consecutive branches into master using

    git merge -s recursive -Xtheirs -Xpatience -Xrename-threshold=20

    However, this left me with the renamed files of the old version in place, and also could not detect the renames.

+6
source share
2 answers

git commit never detects renames. It just writes content to the repository. Renaming (and copies as well) is detected only after the fact, that is, when you run git diff , git merge and friends. This is because git does not save rename / copy information.

+10
source

As pointed out in the comments and another answer, there is no point in setting the detection threshold for renaming in a commit, because this will only change the output of the command, and not what is actually stored in the commit.

However, you can configure the rename detection threshold in the git log command. You do this with the --find-renames . This is basically the result that I wanted to achieve.

+9
source

All Articles