Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8861051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:24:16+00:00 2026-06-14T15:24:16+00:00

I am currently importing a cvs project into git. After importing, i want to

  • 0

I am currently importing a cvs project into git.
After importing, i want to rewrite the history to move an existing directory into a seperate submodule.

Suppose i have a structure like this:


file1
file2
file3
dir1
dir2
library

Now i want to rewrite the history so that the directory library is always a git submodule. Say, split out specified directories into their own submodules / subprojects

This is my currently code:

File rewrite-submodule (which is called)

cd project
git filter-branch --tree-filter $PWD/../$0-tree-filter --tag-name-filter cat -- --all

File rewrite-submodule-tree-filter

    #!/bin/bash

    function gitCommit()
    {
        unset GIT_DIR
        unset GIT_WORK_TREE
        git add -A
        if [ -n "$(git diff --cached --name-only)" ]
        then
            # something to commit
            git commit -F $_msg
        fi
    }

    _git_dir=$GIT_DIR
    _git_work_tree=$GIT_WORK_TREE
    unset GIT_DIR
    unset GIT_WORK_TREE
    _dir=$PWD

    if [ -d "library" ]
    then
        _msg=$(tempfile)
        git log ${GIT_COMMIT}^! --format="%B" > $_msg
        git rm -r --cached lib
        cd library
        if [ -d ".git" ]
        then
            gitCommit
        else
            git init
            gitCommit
        fi
        cd ..
        export GIT_DIR=$_git_dir
        export GIT_WORK_TREE=$_git_work_tree
        git submodule add -f ./lib
    fi

    GIT_DIR=$_git_dir
    GIT_WORK_TREE=$_git_work_tree
    

This code creates the .gitmodules file, but not the submodule commit entry (the line Subproject commit <sha1-hash>, output by git diff) in the main repository and the files in directory library are still versioned in the main repository and not in the subproject repository.

Thanks in advance for any hint

The .gitmodules look like this:

    [submodule "library"]
        path = library
        url = ./library
    

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:24:17+00:00Added an answer on June 14, 2026 at 3:24 pm

    I resolved my own question, here is the solution:

    git-submodule-split library another_library

    Script git-submodule-split:

        #!/bin/bash
    
        set -eu
    
        if [ $# -eq 0 ]
        then
            echo "Usage: $0 submodules-to-split"
        fi
    
        export _tmp=$(mktemp -d)
        export _libs="$@"
        for i in $_libs
        do
            mkdir -p $_tmp/$i
        done
    
        git filter-branch --commit-filter '
        function gitCommit()
        {
            git add -A
            if [ -n "$(git diff --cached --name-only)" ]
            then
                git commit -F $_msg
            fi
        } >/dev/null
    
        # from git-filter-branch
        git checkout-index -f -u -a || die "Could not checkout the index"
        # files that $commit removed are now still in the working tree;
        # remove them, else they would be added again
        git clean -d -q -f -x
    
        _git_dir=$GIT_DIR
        _git_work_tree=$GIT_WORK_TREE
        _git_index_file=$GIT_INDEX_FILE
        unset GIT_DIR
        unset GIT_WORK_TREE
        unset GIT_INDEX_FILE
    
        _msg=$(tempfile)
        cat /dev/stdin > $_msg
        for i in $_libs
        do
            if [ -d "$i" ]
            then
                unset GIT_DIR
                unset GIT_WORK_TREE
                unset GIT_INDEX_FILE
                cd $i
                if [ -d ".git" ]
                then
                    gitCommit
                else
                    git init >/dev/null
                    gitCommit
                fi
                cd ..
                rsync -a -rtu $i/.git/ $_tmp/$i/.git/
                export GIT_DIR=$_git_dir
                export GIT_WORK_TREE=$_git_work_tree
                export GIT_INDEX_FILE=$_git_index_file
                git rm -q -r --cached $i
                git submodule add ./$i >/dev/null
                git add $i
            fi
        done
        rm $_msg
        export GIT_DIR=$_git_dir
        export GIT_WORK_TREE=$_git_work_tree
        export GIT_INDEX_FILE=$_git_index_file
    
        if [ -f ".gitmodules" ]
        then
            git add .gitmodules
        fi
    
        _new_rev=$(git write-tree)
        shift
        git commit-tree "$_new_rev" "$@";
        ' --tag-name-filter cat -- --all
    
        for i in $_libs
        do
            if [ -d "$_tmp/$i/.git" ]
            then
                rsync -a -i -rtu $_tmp/$i/.git/ $i/.git/
                cd $i
                git reset --hard
                cd ..
            fi
        done
        rm -r $_tmp
    
        git for-each-ref refs/original --format="%(refname)" | while read i; do git update-ref -d $i; done
    
        git reflog expire --expire=now --all
        git gc --aggressive --prune=now
    
        
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have perforce that I am importing my project into eclipse from. After
I'm currently working on a VBA macro importing product-requirements into Microsoft Project. I use
I'm currently importing a CSV into an activerecord element but can't choose to parse
I'm testing my project using pylint and currently getting fatal error when importing the
I'm currently using Mongomapper within a Padrino project where I'm importing data from an
We are currently using the Magento API for importing a bunch of products into
I'm currently importing all of our PHP websites into SVN repositories. Each site has
The way im currently importing functions is by putting .py files into the site-packages
I'm importing a plist into an NSDictionary object and want to change the contents
i need to get the current image opened after importing an image sequence to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.