重构为多个文件时如何保留git历史记录 [英] How to preserve git history when refactoring into multiple files

查看:78
本文介绍了重构为多个文件时如何保留git历史记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的SCSS文件很丑.我想将其拆分为多个其他文件,以使其更易于使用.

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.

如果我的文件是

file.scss

我想完成类似的事情,

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

smmdlg都将具有原始files.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?

推荐答案

Git具有基于文件相似性的内置重命名/复制检测功能.为确保启动,首先将file.scss的纯副本复制到所有file-{sm,md,lg}.scss并提交这些文件.然后从这些文件中删除不需要的部分,删除file.scss,然后再次提交.现在例如git log --follow --find-copies file-sm.scss应该显示file-sm.scss的历史记录,包括file.scss的历史记录.

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.

这篇关于重构为多个文件时如何保留git历史记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆