I sometimes modify class names in Java. This results in me requiring to modify the filename as well.
To maintain the history of the files in SVN I use a tool with TortoiseSVN called Repair Move.
In the Check for Modifications view you select two files, one missing and one unversioned. When you right click on one of them there is an option to Repair Move.
This deletes the old file in SVN and adds the new file while attaching the history of the old file. That way when you svn log you can see the entire history since before the filename change.
Does git have an equivalent command? From the workflow that I've read it seems I should do the following:
git mv <old filename> <new filename>
# Make the class name changes to reflect the filename change.
git commit -a -m "Changed filename from Foo.java to Bar.java"
This seems like a long way to do things.
I thought I would be able to usegit mv
once I had moved the file manually and made changes to the file itself. It seems that git mv
is just a wrapper for the mv
command along with adding the change to git.
Is there a way to notify git of a moved file after the move has happened?
It turns out that Git is quite smart at working out when files are renamed.
When you commit a removed file and a new file, the contents of both files are compared for likeness.
If the files meet a certain threshold the commit will automatically change the add and remove file to a rename. Sometimes this will show up once you've git add
and git rm
the file, sometimes after the actual commit.
So for example, Java files change slightly when the filename or package name changes. Git compares the contents of the removed file and the added file, sees that they're mostly the same and marks it as a renamed file.
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