I am using git to manage my dissertation, and have lots of pdf journal articles that I am slowly reorganizing with Finder as my directory structure normalizes over the next few months. I would love to find a way to tell git that these files have simply moved and not deleted and added as new files to avoid repo bloat.
Doing this from the command line is cumbersome when I have to move 20 of 30 files in a folder or folders.
Anyone have a nice way to do this? Or does git do it automatically and I just can't tell?
Thanks!
No matter what you "tell" git, or how you tell it, git will always understand a moved file as "file at this location deleted; file at this other location created". It sometimes reinterprets this as "file moved from this location to this other location" in its output, but no special prompting is needed for it to do this. But fundamentally there is no such thing as a "move" operation in git.
You mention your concern is repo bloat. No need to worry. Even if git sees two files with identical content, it only stores the content once. The content is stored in an object called a BLOB
. The filename is stored in a "directory listing"-like object called a TREE
. So when you move a file, a new entry in a TREE
(possibly in a different TREE
object, if you've moved the file to a different directory) is simply made to point to the already-existing BLOB
.
All of this is automatic. You do of course have to add/commit the changes, but from there it's taken care of.