This is a tricky question. Open source licenses are generally irrevocable. Once you publish something under a license, you can relicense future versions but cannot retroactively change the license. Yet here, you have never directly published the project under the old license.
My take on this is that the MIT license on the old commits is in effect for those commits, and other people are free to use old versions under that license.
But since you haven't yet published this project, you are free to rewrite the Git history. This is fairly advanced Git usage, but you don't have to lose all history. Instead, write a parallel history that keeps the commit metadata and just changes the license file. The git filter-branch
command can be used to automate this process.
For example, we can use the following command to erase a LICENSE
file from the history. The result will be that these old versions are “all rights reserved”; you can later add the intended license when you publish the project.
git filter-branch --index-filter 'git rm --cached --ignore-unmatch LICENSE' HEAD
Another great tool to edit, remove, and reorder commits is git rebase --interactive
. However, filter-branch
allows you to automate edits, and could e.g. also be used to remove license headers from all source files.
Careful: if something goes wrong during the history rewrite, it can be difficult to undo those changes. Before you begin, it is best to create some kind of backup, e.g.:
- create a backup of your project directory incl. the
.git/
directory.
- create a new branch on which you perform the history rewrite. If everything goes well, you can update the old branch to point to the rewritten history (e.g. use
git reset --hard
to move the current branch to a specific commit).
- recently used commits are also available through the
git reflog
.
Example of applying filter-branch:
Given this example history:
$ git log --name-status
commit cb42eda9f7ab47ec55a2698fb7616a74bca4b043 (HEAD -> master)
Author: amon <[email protected]>
Date: Sat Jun 9 20:12:12 2018 +0200
some editing
A bar.c
M foo.c
commit a25c2949ca4c1d397c19510b0b05ebbb0266268b
Author: amon <[email protected]>
Date: Sat Jun 9 20:11:30 2018 +0200
adding LICENSE
A LICENSE
commit 66465e97303c209a239eb212f2dc1b6b76de2cf8
Author: amon <[email protected]>
Date: Sat Jun 9 20:09:55 2018 +0200
initial commit
A foo.c
When I run the license filter, then I get this history:
$ git log --name-status
commit 25ea86eecda1415bf985f1cc03afbc0a30ece281 (HEAD -> master)
Author: amon <[email protected]>
Date: Sat Jun 9 20:12:12 2018 +0200
some editing
A bar.c
M foo.c
commit 505560e9a619b83c71531795cad9ff7a31a93e67
Author: amon <[email protected]>
Date: Sat Jun 9 20:11:30 2018 +0200
adding LICENSE
commit 66465e97303c209a239eb212f2dc1b6b76de2cf8
Author: amon <[email protected]>
Date: Sat Jun 9 20:09:55 2018 +0200
initial commit
A foo.c
As you can see, all commits are still there and have the correct metadata. Those commits that were rewritten now have different IDs. We now have an empty commit where we originally added the license. It is possible to get rid of that as well (e.g. I'd use a git rebase --interactive
to squash it), but it's not terribly important.