git-extras icon indicating copy to clipboard operation
git-extras copied to clipboard

A "git mv" that preserves history

Open dannyroberts opened this issue 10 years ago • 9 comments

This "issue" is more of a request for comments from anyone working on this repo that knows what they're talking about when it comes to git internals. In exchange for comments, I will happily turn this into a PR.

I "discovered" a way to move a directory that also preserves history, including dealing well with merges from code branched before the move: https://gist.github.com/dannyroberts/857b9f7e52acd6b83c89. I say "discovered" because I couldn't find instructions for this anywhere on the internet, but this is what is recommend for doing a "subtree merge" from another repository, and when I tested it, it also worked quite nicely for directories within the same repo.

I think it'd be really great to add to git extras—can any of you who know more than me think of why this might specifically be a bad idea?

dannyroberts avatar Mar 17 '15 19:03 dannyroberts

Seems like a nice use case, I would like to know how @spacewander feels about this.

hemanth avatar Mar 18 '15 05:03 hemanth

@dannyroberts Can you describe what occasions we can use it? Will it be used frequently? This looks like a good tip, is it useful enough to be a tool?

spacewander avatar Mar 20 '15 09:03 spacewander

I think the main use case is in reorganizing a large project that has many modules for example. You might feel stuck because it doesn't feel worth it to move whole directories to more logical places if it means that the entire history of that module is basically lost (think git log, git blame on individual files), and if there's a large team of people working on the project and branches they have with changes to the files you moved will be completely unmergeable.

If you use git move-tree or whatever we'd theoretically call this git-extra, then you can feel a lot freer to reorganize code without disrupting your entire team's workflow.

dannyroberts avatar Mar 20 '15 15:03 dannyroberts

It sounds good. What about your opinions? @hemanth

spacewander avatar Mar 22 '15 13:03 spacewander

if there's a large team of people working on the project and branches they have with changes to the files you moved will be completely unmergeable.

^ sounds like a highly probable scenario.

hemanth avatar Mar 22 '15 16:03 hemanth

Ok so this sounds like a valuable thing for me to script up? I'll set some time aside this weekend to do a first pass on it and do some more testing. If all goes well you'll get a PR from me shortly

dannyroberts avatar Mar 23 '15 14:03 dannyroberts

:shipit:

hemanth avatar Mar 23 '15 16:03 hemanth

(Not too surprisingly I got distracted in the middle of my short weekend coding session. Making more time next weekend.)

dannyroberts avatar Mar 30 '15 14:03 dannyroberts

NP, take your time :+1:

hemanth avatar Mar 30 '15 16:03 hemanth