Git rewrite history move folders and files up to parent folders

I want to rewrite history and move all files and folders in a certain folder 2 folders up for all branches.

My repo looks like:

  • How to ignore IDE settings on Git?
  • Local Client server Git setup for Xcode projects
  • How to set nano up for git commit messages with line length limits
  • Why is git checkout of a branch becomes detached?
  • Skip auto loading last session when Vim is launched from git commit
  • git: prohibit to accidentally push merge testing into master
    • src
      • v105
      • src
        • files
        • folders
    • tools
    • lib

    I want it to be:

    • src
      • files
      • folders
    • tools
    • lib

    I know how to rewrite history for removing files recursively in a folder


    git filter-branch --force --index-filter 'git rm -rf --cached --ignore-unmatched somefolder/somefolder'
    --prune-empty --tag-name-filter cat -- --all

    I also know the git mv command.

    Using the following command the files and folders are all moved to the correct folder. The first patterns matches all files and folders within the provided folder. The second pattern matches all files and folders starting with a dot.

    git mv src/v105/src/* src/v105/src/.[^.]* src

    However when I want to use this command with the rewrite history command it doesn’t work.


    git filter-branch --force --index-filter 'git mv src/v105/src/* src/v105/src/.[^.]* src --cached --ignore-unmatched'
    --prune-empty --tag-name-filter cat -- --all

    Because the src folder does not exist in all cases in my commit history it tells me it can’t find the src dir. Any ideas how to solve this?

    UPDATE


    git filter-branch --force --index-filter 'if [-d 'src/v105/'] then git mv src/v105/src/* src/v105/src/.[^.]* src fi'
    --prune-empty --tag-name-filter cat -- --all

    results in unexpected end of file.

  • Does passphrase need to be the same as the git hosting provider password
  • Git - how to update an old commit
  • Github automatically deletes a file during clone
  • why merge does not cause conflict
  • How to Move a Tracked File to Untracked using Visual Studio Tools for Git
  • Git submodule update overwritten
  • One Solution collect form web for “Git rewrite history move folders and files up to parent folders”

    The filter commands don’t need to be git commands. Could it be as simple as this?

    git filter-branch --force -tree-filter 'mv src/src/files src/; mv src/src/folders src/'

    Git Baby is a git and github fan, let's start git clone.