All Projects → potherca-bash → git-split-file

potherca-bash / git-split-file

Licence: GPL-3.0 license
Split a file in a git repository without losing the git history.

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to git-split-file

php-client
PHP SDK client for Split Software
Stars: ✭ 14 (-44%)
Mutual labels:  split
tss-rb
A Ruby implementation of Threshold Secret Sharing (Shamir) as defined in IETF Internet-Draft draft-mcgrew-tss-03.txt
Stars: ✭ 22 (-12%)
Mutual labels:  splitting
SplittableViewKit
A cell of IndexPath(row: 0, section: 0) in UITableView is automatically moved to left view when device rotated.
Stars: ✭ 39 (+56%)
Mutual labels:  split
webpack-everything
Vue cli template with webpack, vuex, vue router, eslint, image compression, graphql, apollo, server side rendering, code splitting and progressive web app (PWA) capabilities
Stars: ✭ 19 (-24%)
Mutual labels:  splitting
splitter
React component for building split views like in VS Code
Stars: ✭ 351 (+1304%)
Mutual labels:  split
AEScript-Explode-Shape-Layer
Extract shapes from a shape layer to individual layers
Stars: ✭ 37 (+48%)
Mutual labels:  split
git-split-diffs
GitHub style split diffs in your terminal
Stars: ✭ 2,423 (+9592%)
Mutual labels:  split
react-typewriter-js
Simple vanilla JS script to simulate text typewriting effect.
Stars: ✭ 18 (-28%)
Mutual labels:  split
thinkeys
Split ortholinear custom replacement keyboard with TrackPoint for ThinkPad laptops.
Stars: ✭ 167 (+568%)
Mutual labels:  split
monorepo-split-github-action
Github Action for Monorepo Split
Stars: ✭ 56 (+124%)
Mutual labels:  split
git-commands
Custom power-user git commands.
Stars: ✭ 45 (+80%)
Mutual labels:  git-addons
react-native-component-splitter
VS Code Extension allows splitting React Native Component into Sub-Component
Stars: ✭ 33 (+32%)
Mutual labels:  split
ruby-client
Ruby SDK client for Split Software
Stars: ✭ 22 (-12%)
Mutual labels:  split
git-global
Keep track of all your git repositories.
Stars: ✭ 23 (-8%)
Mutual labels:  git-addons
git-issue
Bug tracker based on git
Stars: ✭ 16 (-36%)
Mutual labels:  git-addons
git-faker
👻 You can be the best GIT-COMMITTER in the planet.
Stars: ✭ 30 (+20%)
Mutual labels:  git-addons
allotment
A React component for resizable split views
Stars: ✭ 359 (+1336%)
Mutual labels:  split
ModuleServices
Reusable ViewController with TableView, split in Sections (called here modules) that help you to develop faster in Swift
Stars: ✭ 21 (-16%)
Mutual labels:  split
patchify.py
A library that helps you split image into small, overlappable patches, and merge patches into original image.
Stars: ✭ 102 (+308%)
Mutual labels:  split
react-client
React JS SDK client for Split Software
Stars: ✭ 23 (-8%)
Mutual labels:  split
permalink
/

Git Split File

Split a file in a git repository without losing the git history.

Introduction

Usually when a file in a git repository is split into several different files, the history gets lost.

Often this is not desirable.

git-split-file allows for split files to retain their history.

Splitting a file still needs to be done manually but this script will take care of branching/moving/renaming/committing/merging/etc. the split files.

See the usage section for details on how to do this.

Installation

Clone or download this repository or the single file git-split-file.sh

Usage

In short all that needs to be done is manually split a file and call git-split-file

There are, however, some details to take into account.

Manually splitting the file

You have a file in a git repository that you would like to split into several files.

First create a directory the split files can be placed in. This directory does not have to reside in the git repository the file to split is in.

Next split that file into several different files. The more of the order and whitespace is left intact, the more of the history will also be left intact.

Under some circumstances it is desirable to have a truncated version of the file that has been split, under other circumstances the file that has been split can be removed completely. Both scenarios are supported.

In the scenario where the file is to be deleted, just leave the contents of that file as-is. git-split-file will simply remove the file for you.

In the scenario where a change version of the file is to remain in the repository, add a version of the file as it should eventually be in the directory that also holds the other split files. git-split-file will commit the changes for you. It is possible to tell the script to either leave the file in the same location or move it to the same location as the other split files.

Calling the script

As the final result can live outside of the repository, the script can easily be run on a clone to verify everything works out as desired.

In order to function, the script needs to know a few things:

  • The source file that is to be split (the source file)
  • The directory where the split files are located (the source directory)
  • The location where the split files should be placed in the repository (the target path)
  • Whether to delete or move the source file. (the split strategy)

Currently moving the source file to another location than the target path is not supported.

How it works

As a picture might communicate matter more clearly than mere words, consider the following:

        A---bN--cN      split branch N
       /         \
      A---B---C   \     split branch one
     /         \   \
    A-------D---E---eN     source branch
   /                  \
--A--------------------F--  root branch
  • A is the last known commit on the root branch.
  • A separate branch is made to function as the "source" to and from other branches are split off.
  • For each file in the source directory a copy of the source file is created (using git mv $SOURCE $TARGET) leading to commit B (and bN).
  • The content of the copied file is updated (using cat $CONTENT > $TARGET and git add/commit $TARGET) leading to commit C (and cN).
  • The content of the source file is updated leading to commit D.
  • Each split branch is then merged into the source branch, resolving any conflicts that occur, leading to commit E (and eN).
  • When all branches have been merged, everything is merged back to the root branch. Commit F now has all of the changes.

Origin / Motivation

When working in low-quality code-bases that have grown organically over time, it is not uncommon to encounter files that span several (tens of) thousands of lines.

For various reasons it is desirable to split such files into smaller files.

Instead of doing this by hand, it made more sense to automate parts of the process.

Development

There is currently only one test, in a separate repo. Yes, more tests do need to be added. Feel free to contribute some! 😉

License

This project has been licensed under GPL-3.0+ License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].