Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I control the rename threshold when committing files under git?

I'm trying to place into git's history successive snapshots of a specific project. I am doing 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 the commit recognizes file renames only when 100% of the file contents remain the same. Is there a way to influence rename detection of git commit to make it find renames where the file contents have changed a bit? I see that git merge and git diff have various options for controlling the rename threshold, but these options do not exist for git commit.

Things I have tried:

  • Locating the renamed files with a home-brew script, and performing a commit with the original files renamed to their new locations before committing the new file contents. However, this introduces an artificial commit, and seems inelegant, because it doesn't use git's rename detection functionality.
  • Creating a separate branch for each snapshot and then merging the successive branches onto 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, while also failing to detect the renames.

like image 585
Diomidis Spinellis Avatar asked Feb 12 '13 12:02

Diomidis Spinellis


People also ask

How do I commit case-sensitive only filename changes in git?

Git has a configuration setting that tells it whether to expect a case-sensitive or insensitive file system: core. ignorecase . To tell Git to be case-senstive, simply set this setting to false . (Be careful if you have already pushed the files, then you should first move them given the other answers).

How does git handle rename?

Git keeps track of changes to files in the working directory of a repository by their name. When you move or rename a file, Git doesn't see that a file was moved; it sees that there's a file with a new filename, and the file with the old filename was deleted (even if the contents remain the same).

Is git case-sensitive for file names?

The Windows and macOS file systems are case-insensitive (but case-preserving) by default. Most Linux filesystems are case-sensitive. Git was built originally to be the Linux kernel's version control system, so unsurprisingly, it's case-sensitive.

Is a git command that allows you to rename files?

For renaming files or folders use nothing but the git mv command. git mv takes at least two arguments, a source and a destination. If you want to move several files to a single path you may specify n sources but the last argument is the destination.


2 Answers

git commit never detects renames. It just writes content to the repository. Renames (and copies as well) are only detected after the fact, i.e. when running git diff, git merge and friends. That's because git does not store any rename/copy information.

like image 111
Michael Wild Avatar answered Oct 13 '22 22:10

Michael Wild


As indicated in comments and another answer, it doesn't make sense to adjust the rename detection threshold in the commit, because this would only change the command's output, not what's actually stored in the commit.

What you can do however, is adjust the rename detection threshold in the git log command. You do this by using the --find-renames parameter. This mostly accomplishes the result I wanted to achieve.

like image 28
Diomidis Spinellis Avatar answered Oct 14 '22 00:10

Diomidis Spinellis