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 7606231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:21:28+00:00 2026-05-31T00:21:28+00:00

I have a directory structure in my repository: |-repository/ | | |-repository/fileOne | |

  • 0

I have a directory structure in my repository:

|-repository/
|  |  |-repository/fileOne
|  |
|  |-subOne/
|  |  |-subOne/fileTwo
|  |
|  |-subTwo/
|     |-subTwo/fileThree

I want to move the directory subOne into a different repository. To do that, I’m separating subOne using git-filter-branch like so:

$ git filter-branch --subdirectory-filter subOne --prune-empty

This leaves me with a branch history that looks like this:

$ git log --oneline
0c0ea11 subOne history
6318bba subOne history
c96fddb Initial commit

This is exactly what I want; from another repository I can do a git fetch and git merge, which adds subOne and history into the other repository. That’s great.

However, git-filter-branch has removed subOne. Checking the directory structure on my branch:

$ ls
fileOne
$ pwd
/this/is/a/path/repository

pwd should read: /this/is/a/path/repository, but ls should show subOne inside the repository. What I’ve got instead is the files from subOne moved upwards, and the directory removed.

How can I extract subOne without losing the directory?

  • 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-05-31T00:21:29+00:00Added an answer on May 31, 2026 at 12:21 am

    pwd should read: /this/is/a/path/repository, but ls should show subOne inside the repository. What I’ve got instead is the files from subOne moved upwards, and the directory removed.

    It turns out this is the default operation of git-filter-branch --subdirectory-filter. Quoting from man git-filter-branch:

    The result will contain that directory (and only that) as its project root.

    To fix this, I want to shift everything in / to /subdirectory. Luckily, there’s a piece of voodoo-looking code in man git-filter-branch, under EXAMPLES:

    To move the whole tree into a subdirectory, or remove it from there:
           git filter-branch --index-filter \
                   'git ls-files -s | sed "s-\t\"*-&newsubdir/-" |
                           GIT_INDEX_FILE=$GIT_INDEX_FILE.new \
                                   git update-index --index-info &&
                    mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD
    

    EDIT: THIS WILL NOT WORK ON MAC OS X. See my question here for more information. BSD sed is not the same as GNU sed, which is annoying. To run that example on OS X, change sed to gsed; the filter then works quite well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a directory structure of directories and files that I want to render
I have a remote repository in a different directory structure than the master. A
I have a directory structure that looks like this: /a/f.xml /b/f.xml /c/f.xml /d/f.xml What
I have a subversion repository with a directory structure: frontend backend + a +
I have a directory structure in my SVN repository which is pretty standard: /project1
I have a mercurial repository with the following directory structure: / /system /applications /applications/client1
In my Hg repository (at Google Code) I have a directory that shouldn't be
Let's pretend I have a project directory that isn't a git repository. This project
I have a single-person single-folder mercurial repository. The directory structure is simple: P104 lecture_notes
I have directory structure like so: |-- ROOT |-- Project1 | |-- application |

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.