How to delete a file, rename another file to the deleted filename in Git

My team has been working on a game that was 16 bits originally. We have since simplified to 10 bits. My understanding of ideal Git strategy would be to create a branch 10Bit, and change the code to 10 bits without altering the filenames; however, my teammate made copies of several files, with 10Bit appended to the filename, without deleting the old file. This was several commits ago, and now our filesystem looks like this:

Master.sv    # <--Old 16-bit code, not used in 10-bit
Master10Bit.sv
Master_Constraints.xdc # <-- same
Master_Constraints10Bit.xdc
Slave.sv    #    <-- same
Slave10Bit.sv

We want to get back to the original names, without the 10Bit part. But if I do

git rm Master.sv
git mv Master10Bit.sv Master.sv

git doesn't see this as a simple file rename. Instead, git status or a git diff shows that Master10Bit.sv was deleted, and Master.sv was changed significantly. This isn't what happened, though; a git diff should show that Master.sv was deleted, and that Master10Bit.sv was renamed to Master.sv.

Likewise for all the other files.

What's a good way to go about this change?

1 answer

  • answered 2018-12-05 20:23 apapillon

    You must remove Master.sv, commit changes and finaly rename Master10Bit.sv to Master.sv.

    git rm Master.sv
    git commit -m "Remove old files"
    git mv Master10Bit.sv Master.sv
    git commit -m "Rename files"