Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move a file/directory but still merge changes easily?

Tags:

I've read in various FAQs that git doesn't explicitly track renames/moves, preferring to look for identical (or in some situations similar?) files. That's great, but will it cope with this situation: a friend's remote repository has a new feature (i18n) involving some new files at debian/po/*.po. I have my own fork of this project, and want to merge this feature but put the files at just po/*.po (I can do that as two commits, or whatever is necessary). I expect the remote repo will continue to receive updates to the feature, and I want to just merge/cherry-pick those commits and have them applied to the files in my new location. Can git do that, perhaps with some sort of mapping of "these files have moved over here now"? Or is it more pain than it's worth and should I just accept the slightly odd debian path in my repo?

like image 378
Chris Boyle Avatar asked Nov 15 '09 23:11

Chris Boyle


2 Answers

use git mv and everything will be AOK.

Why not just try it instead of asking? You can always reset easily in git. :)

like image 139
Pod Avatar answered Nov 14 '22 02:11

Pod


Git lacks a mechanism to indicate that you expect there to be path renames and updates when doing the diff between two projects/branches etc.

There are the various file rename options available (such as -M and --patience) but can be slow.

As already stated, the path renames don't affect the repository itself because it is simply a snapshot of your content (blobs) and structure (tree nodes). If all you have done is added an extra top level directory then all the trees and blobs below are unchanged and require zero additional storage. All you need is the one tree node for your commit and one tree node for the new tld. Dead easy. Git handles that part no problem.

It is only when you want to do a comparison (and any patches) that it matters. It would be nice to have say a -P option that indicates that you expect some path renames and for the diff to thereby cope easily. It's not good seeing 200 file deletes and 200 new files ;-)

Finding out how to add a -P option is another one of my 'to do' list items (I hope I get some time for it).

like image 33
Philip Oakley Avatar answered Nov 14 '22 02:11

Philip Oakley