summaryrefslogtreecommitdiff
path: root/src/Git:Changing_Project_Licensing.ascii
blob: d2967d602c29b6c9bb0127a7e44e8bc88c47fe7b (plain)
    1 Git:Changing Project Licensing
    2 ==============================
    3 :author: Aaron Ball
    4 :email: nullspoon@iohq.net
    5 
    6 
    7 == {doctitle}
    8 
    9 I'm unsure about the legality of doing something like this. I think though that
   10 this probably shouldn't be used if you've already released your project. If
   11 however you have not yet released and have changed your mind to use a different
   12 license prior to its release, this may be just the post for you.
   13 
   14 I recently was working on a project that prior to releasing, I decided upon
   15 using the Apache V2 license. After something thinking though (and about 10
   16 commits), I decided I wanted to release this project under the copyleft
   17 http://www.gnu.org/licenses/gpl-2.0.html[GPL v2] license.  Unfortunately
   18 though, I had already commited the LICENSE file as well as put the shortened
   19 license header at the top of my program's files.  Thankfully, git has a
   20 solution to fix this problem. However, we will have to fix this in two steps
   21 since we will be rewriting a certain file as well as deleting another entirely
   22 (LICENSE).
   23 
   24 [[removing-a-file-section-throughout-history]]
   25 == Removing a File Section Throughout History
   26 
   27 ----
   28 git filter-branch -f --tree-filter "if link:\$(grep_'Apache'_somefile)[\$(grep 'Apache' somefile)]; then sed -i -e '2,16d' somefile; fi"
   29 ----
   30 
   31 What this does is modify the contents of file **somefile**. Effectively, for
   32 each commit in history (+git filter-branch --tree-filter+), this checks if the
   33 file *somefile* contains the string __Apache__. If it does, it then uses sed to
   34 do an inline edit to delete lines 2-16 (those are the lines containing my
   35 license header).  You will likely need to change those since not all license
   36 headers are the same length (and don't start at line 2).
   37 
   38 [[deleting-a-file-from-history]]
   39 == Deleting a File From History
   40 
   41 Now that we've cleaned out the license header, we just need to remove the
   42 LICENSE file from all of history so we can put a new one in. To do this, we're
   43 going to use the *--index-filter* switch.
   44 
   45 ----
   46 git filter-branch -f --index-filter 'git rm --cached --ignore-unmatch ./LICENSE'
   47 ----
   48 
   49 Something to note about the _git rm_ command we just ran. Notice the
   50 _--ignore-unmatch_ switch. That will make git rm return a 0 status even if the
   51 specified file is not found. Basically, that means that it will keep the git
   52 filter-branch command from exiting when it happens upon a commit where the file
   53 doesn't currently exist.
   54 
   55 
   56 
   57 Category:Git
   58 
   59 
   60 // vim: set syntax=asciidoc:

Generated by cgit