Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Problem splitting repository into two using git

numberwhun
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 26, 2018

Hello all! 

I am following the instructions here, as they are pretty much the operation(s) that I need to perform as I am wanting to split out part of an existing repository into another repository.  

Per the above link, I have cloned the original repository into a new directory name, removed the origin and put together the 'git filter-branch' command to contain all of the directories in the current repository that I do not need.  When I run the command, I get the following:

 


$ git filter-branch --index-filter 'git rm --cached -r ansible AWS git-files named-config puppet rpm-spec sbin tftpboot var' -- --all
Rewrite 89840b3a5dbef0f2cecd6cb5d3b5dccdbf3939c7 (1/3387) (0 seconds passed, remaining 0 predicted) fatal: pathspec 'ansible' did not match any files
index filter failed: git rm --cached -r ansible AWS git-files named-config puppet rpm-spec sbin tftpboot var

 

The names that I listed after the '-r' are the names of the directories, and they actually exist in the directory where I am.  Mind you, this is a repository that I just finished converting from SVN to Git and this is a fresh clone of the repo after the conversion and commit. 

Is there something I am missing?  Due to my conversion is there something I need to do first?  I greatly appreciate any help that you can provide.

1 answer

0 votes
Alasdair Bannatyne
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 17, 2018

Did you ever work this out, Jefferson? I find myself in the same situation.

numberwhun
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
December 30, 2018

Actually, yes, I did.  Sorry for not posting it.  Here is the solution:

-------------------------------------------

 

Check out a full copy of your repository

This is crucial to ensuring that you get everything you need to, especially if you are going to include all of your branches and releases (we are only worried about the branches). 

 

Create the authors-transform.txt file

In order to do the conversion, you will need the authors-transform.txt file, which maps the author user ids to their name/email addresses.  To create it, be in your checked out "full" svn repo and run the following from its root:

> svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt

 

That will produce a file containing all the users, but it isn't exactly what we need.  You will want each entry in the form of:

username = Name <email_address>

 

Clone svn repo with git

To run this, make sure that you are in the root directory of the repository you checked out above ( to be clear, you should be in the directory you were in, when you issues the 'svn co' command for the syseng repo above.  So if you created a directory called syseng-20171212 and issued the command from that directory, that is the direcotry you want to be in.  Hint:  You are in the correct directory if you do an ls and see a "syseng" directory in the directory where you are).

NOTE: Make sure the output of 'ssh-add -l' contains the ssh key that you have setup in skunkworks, otherwise you will be entering your password more times than you will care to during the following command's run.

git svn clone <url_to_repo> --no-metadata -A authors-transform.txt -t tags -b branches -T trunk ~/repos/syseng-git

 

Make sure that the output competes without any errors.  Once completed, you can change directories to where you specified to as an output directory, and running 'git log' should show your full commit history.  

 

Convert SVN tags to Git tags

All tags need to be converted to git tags.  The following code is in converttags.sh script:

#!/bin/bash

for t in `git branch -r | grep 'tags/' | sed s_tags/__` ; do     git tag $t tags/$t^     git branch -d -r tags/$tdone

 

Checkout Branches

Now, all branches that you want imported into the new git repo need to first be branched to git.  Typically this is done by checking each branch out into your repository.

First you need to show all the available branches:

> git branch -r

 

Now you need to checkout each branch that you want to be included in the repo when you push it to the server.

So in your repository, for each branch, you will do:

> git checkout -b <branch_name> <branch_name>Checking out files: 100% (143489/143489), done.Switched to a new branch 'puppet'

 

You should use the same name for both <branch_name> areas.  That way the same name is kept for each.

Run the above for all the branches that you want to bring with you.  They must be checked out to be available. 

 

*Note:  At any time after you do the 'git svn clone' you can do a 'git remote -v' and see where the repo that is being sourced is.  Because we are working in our converted repo, it shouldn't be pointing anywhere.

 

Set your remote for your stash repo

At this point, we should have all tags converted and all branches checked out.  Now we need to set our remote to be the stash repository.  If you have an empty stash repository, go to the page for the source and it will provide you the connect string to use.  After you set it, you can verify it is set with 'git remote -v'.

 

Push your code and tags to the Stash server

Once your remote is set, you can now push your repo (and tags) to the Stash server.   The format for doing this is:

> git push <REMOTE_NAME> <BRANCH_NAME>

REMOTE_NAME is typically 'origin', as was used in the previous command to set the remote.  BRANCH_NAME is the branch that you have checked out that you would like to push to the remote.

We will be pushing both the repo and its associated tags to the remote.  We will do that with the following commands:

> git push origin master> git push origin master --tags

Those are two separate command and both need to be done.  You will get output like this:

> git push origin masterCounting objects: 26945, done.Delta compression using up to 8 threads.Compressing objects: 100% (9181/9181), done.Writing objects: 100% (26945/26945), 586.86 MiB | 20.65 MiB/s, done.Total 26945 (delta 16196), reused 26171 (delta 15499)To ssh://git@stash-dev.veracode.local:7999/syseng/veraforge.git * [new branch]      master -> master > git push origin master --tagsCounting objects: 35403, done.Delta compression using up to 8 threads.Compressing objects: 100% (16976/16976), done.Writing objects: 100% (35403/35403), 4.59 GiB | 13.04 MiB/s, done.Total 35403 (delta 14063), reused 34550 (delta 13360)

 

You will need to checkout each and every branch that you want pushed to the remote and do the two 'git push' commands for each branch.  Only after doing that for each branch, will the individual branches be available in Stash (a.k.a. BitBucket).

NOTE: In the interest of disclosure, instead of checking each and every branch out, you can simply to the 'git push origin <branch_name>' after the initial push of the master branch and each branch will then appear in the branches list.

 

Once you have completed these steps, you should be able to go to your Stash interface and browse the code, branches, tags and even the commit history for your repository.

 

------------------------------------------

 

Granted, there are apparently 'conversion tools' that you can use, but I am old-school and like knowing how to do things manually.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events