tj / git-extras

GIT utilities -- repo summary, repl, changelog population, author commit percentages and more
MIT License
17.34k stars 1.21k forks source link

A "git mv" that preserves history #335

Open dannyroberts opened 9 years ago

dannyroberts commented 9 years ago

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?

hemanth commented 9 years ago

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

spacewander commented 9 years ago

@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?

dannyroberts commented 9 years ago

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.

spacewander commented 9 years ago

It sounds good. What about your opinions? @hemanth

hemanth commented 9 years ago

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.

dannyroberts commented 9 years ago

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

hemanth commented 9 years ago

:shipit:

dannyroberts commented 9 years ago

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

hemanth commented 9 years ago

NP, take your time :+1: