Moving files in Git

Post Reply
FluffyFreak
Posts: 1256
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Moving files in Git

Post by FluffyFreak » Thu Jun 20, 2019 8:19 pm

Recently a lot of files have been, and are being, moved around into subfolders etc.

This is making it really difficult to backtrack and follow the history of files which on a project this long lived is really important for tracking bugs and functionality.

There's an easy way to avoid this being a problem though, because Git can handle files being moved, it can detect them if they're identical before and after the move so long as they're committed immediately.

So I'm asking if we can follow this process for moving files around:
1. Do NOT change the files in any way
2. Move the unchanged file to the new location
3. Commit the moved files immediately
4. Then fixup the files for their new location or make any other changes!

If we do this, and if it works, then following changes back through the history of the files should be much easier.

What do people think?

impaktor
Posts: 780
Joined: Fri Dec 20, 2013 9:54 am
Location: Tellus
Contact:

Re: Moving files in Git

Post by impaktor » Fri Jun 21, 2019 9:17 pm

Well, "git status" before commit should show if git correctly understood that the files have just been "renamed" which is what git calls a moved file, I think.

Code: Select all

git mv <from> <to>

GunChleoc
Posts: 37
Joined: Sat Nov 30, 2013 12:57 pm
Contact:

Re: Moving files in Git

Post by GunChleoc » Sat Jun 22, 2019 11:15 am

Yes, definitely use the git mv command.

FluffyFreak
Posts: 1256
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: Moving files in Git

Post by FluffyFreak » Tue Jun 25, 2019 10:20 am

Is there a way to reassociate files that have already been moved?

FluffyFreak
Posts: 1256
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: Moving files in Git

Post by FluffyFreak » Tue Jun 25, 2019 10:22 am

There are pending PR's where files have been moved by just moving them, but with edits, so Git doesn't automatically track them. Even git mv just moves them with a commit, there's no other magic "move" command it just does what I've suggested above as far as I can tell.

impaktor
Posts: 780
Joined: Fri Dec 20, 2013 9:54 am
Location: Tellus
Contact:

Re: Moving files in Git

Post by impaktor » Tue Jun 25, 2019 5:02 pm

Even git mv just moves them with a commit
Well, yes, just doing a chmod on a file will create a commit, but as long as it's not removing all old code, and creating all code anew, then it's fine, and git mv should behave sanely.

Any example of such a PR?

FluffyFreak
Posts: 1256
Joined: Tue Jul 02, 2013 1:49 pm
Location: Beeston, Nottinghamshire, GB
Contact:

Re: Moving files in Git

Post by FluffyFreak » Tue Jun 25, 2019 7:43 pm

Every commit that has moved something into the `\src\ship` folder

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest