Home > Mobile >  Rewriting Git history to place all work in a subfolder instead of root
Rewriting Git history to place all work in a subfolder instead of root

Time:01-20

I have a simple repository with linear history where work was done in the root folder. I would like to rewrite history so that all the work from every commit looks like it happened in the /server directory instead of the root directory.

In the end, the repository should have a single folder called server in its root, with all my project's files and folders now (and at all points of history before) located in /server.

CodePudding user response:

git filter-branch --commit-filter '  
            toptree=`printf "040000 tree %s\\tserver" $1 | git mktree`
            shift
            git commit-tree $toptree "$@"
    ' -- --branches

CodePudding user response:

You are looking for git filter-repo. This is just the kind of thing it was written to do; see #3 in the rationale section of the readme.

https://github.com/newren/git-filter-repo#design-rationale-behind-filter-repo

  •  Tags:  
  • Related