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:
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.
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).
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).
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With