Skip to content

WPConstructor/pre-versions-git-importer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 

Repository files navigation

WPConstructor Pre-Versions Git Importer

WPConstructor Pre Versions Git Importer logo

This script imports pre-versions folders (like 0.1.0, 0.2.0, etc.) into a Git repository as sequential commits.

Why I Created this Script: A Bridge from Old Habits to Modern Version Control

As a developer, I used to manage my projects by creating separate folders for each pre-version and keeping manual changelogs. Since I was programming mostly on my own, I was always worried about losing files or making mistakes if I tried using Git or SVN. For a long time, this “folder-based versioning” was my comfort zone.

Now that I’ve finally started working with Git and SVN, I really enjoy the workflow and see how much easier it makes version control. To bridge the gap with my older projects, I created the wpcn-pre-versions-git-importer.php script. It lets me import my previous folder-based versions directly into Git, so I can preserve my old history while moving forward with modern version control tools.

Features

  • Automatically detects Git installation.
  • Imports multiple pre-versions folders sequentially.
  • Commits each version automatically.
  • Sets each commit date to the newest file modification time in the version folder.
  • Supports custom commit dates via a dates.txt file.
  • Works on both Windows and Unix-like systems.

Requirements

  • PHP 7.4+ or higher installed as CLI version.
  • Git installed and available in your system PATH.
  • Pre-version folders named in the format 0.*.* (e.g., 0.1.0, 0.2.0).
  • A main project directory containing the version folders.

Installation

1. Create version directories

Organize all versioned code inside separate version directories:

0.1.0/
0.2.0/
0.3.0/
...

Each directory should contain the complete codebase for that specific version.

2. Download the importer script

Download the importer file directly into the same directory where you want to run the import:

curl -O https://raw.githubusercontent.com/WPConstructor/pre-versions-git-importer/main/wpcn-pre-versions-git-importer.php

The directory should contain:

wpcn-pre-versions-git-importer.php
0.1.0/
0.2.0/
...

3. Create the history file

Create either a dates.txt file or a commits-history.csv file to define the version dates and commit history.

Example:

dates.txt

or:

commits-history.csv

The importer will use this file to generate the required Git history for each version.

4. Run the importer

Execute the importer with PHP:

php wpcn-pre-versions-git-importer.php

The script will process the version directories and create the Git commit history based on the provided dates and version data.

Usage

php wpcn-pre-versions-git-importer.php
  • The script will create a temporary repo folder inside the project directory.
  • It will import each pre-version folder into Git, creating a commit for each version.
  • The commit date of each version is automatically set to the newest file modification date in that version folder or defined in dates.txt or commits-history.csv.

Optional: Custom Dates via dates.csv

If the file modification times are incorrect or unreliable, you can provide a dates.csv file in the project root directory.

The file should contain comma-separated version-date pairs in the following format:

0.1.0,2025-05-05
0.2.0,2025-10-10
0.3.0,2025-11-01
  • Each entry maps a version to a specific commit date.
  • If a version exists in dates.csv, its date will override the automatically detected file modification date.
  • Versions not listed in dates.csv will still use the newest file modification time as a fallback.

Optional: Custom Commit Messages via commits-history.csv

By default, the importer creates commits using the following message format:

Import Version 0.x.x

If you want to customize the commit messages, you can provide a commits-history.csv file in the project root directory.

The file should contain CSV entries with the version and its corresponding commit message in the following format:

0.1.0,My first release
0.2.0,My second release
0.3.0,"Quote the message when using commas, yes!"
  • Each entry maps a version directory to a custom Git commit message.
  • If a version is found in commits-history.csv, the provided message will be used instead of the default message.
  • If a version does not have an entry in commits-history.csv, the importer will use the default commit message:
Import Version 0.x.x



Directory Structure Example

project-root/
├── 0.1.0/
├── 0.2.0/
├── 0.3.0/
├── dates.csv
├── commit-history.csv
└── wpcn-pre-versions-git-importer.php

After running the script, the repo folder will contain a Git repository with all pre-versions imported.

Notes

  • The script safely skips the .git folder while clearing files for the next version.
  • On Windows, it uses xcopy and rmdir for file operations.
  • On Unix-like systems, it uses cp and rm -rf.
  • Commit dates reflect the newest file in each version folder by default.
  • If dates.csv is provided, its values take precedence over file timestamps.
  • If commit-history.csv is provided, the defined commit message in commit-history.csv is used.

License

MIT License © 2026 by WPConstructor https://wpconstructor.com/contact/

About

Import old-style pre-version folders (e.g., 0.1.0, 0.2.0) into a Git repository as sequential commits, preserving history and simplifying version tracking.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors

Languages