Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve git history when refactoring into multiple files

Tags:

git

I have a SCSS file that is ugly. I want to split it up into multiple other files to make it easier to work with.

If my file is,

file.scss

I want to finish with something like,

file.scss
file-sm.scss
file-md.scss
file-lg.scss

sm, md, and lg will all have significant portions of the original files.scss so I want to preserve/copy history on them to make it easier on future development and future developers.

How can I refactor a file into multiple new files and preserve, or copy over, history to the new files?

like image 258
Jeff Avatar asked Aug 02 '16 20:08

Jeff


1 Answers

Git has built-in rename / copy detection based on file similarity. To ensure it kicks in, first do a plain copy of file.scss to all of file-{sm,md,lg}.scss and commit these files. Then delete the unwanted portions from these files, remove file.scss, and commit again. Now e.g. a git log --follow --find-copies file-sm.scss should show file-sm.scss's history including the one of file.scss.

like image 137
sschuberth Avatar answered Sep 23 '22 03:09

sschuberth