This script imports pre-versions folders (like 0.1.0, 0.2.0, etc.) into a Git repository as sequential commits.
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.
- 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.txtfile. - Works on both Windows and Unix-like systems.
- 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.
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.
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.phpThe directory should contain:
wpcn-pre-versions-git-importer.php
0.1.0/
0.2.0/
...
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.
Execute the importer with PHP:
php wpcn-pre-versions-git-importer.phpThe script will process the version directories and create the Git commit history based on the provided dates and version data.
php wpcn-pre-versions-git-importer.php- The script will create a temporary
repofolder 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.txtorcommits-history.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.csvwill still use the newest file modification time as a fallback.
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
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.
- The script safely skips the
.gitfolder while clearing files for the next version. - On Windows, it uses
xcopyandrmdirfor file operations. - On Unix-like systems, it uses
cpandrm -rf. - Commit dates reflect the newest file in each version folder by default.
- If
dates.csvis provided, its values take precedence over file timestamps. - If
commit-history.csvis provided, the defined commit message incommit-history.csvis used.
MIT License © 2026 by WPConstructor https://wpconstructor.com/contact/
