Reputation: 6568
I have a project I've been working on some experimental changes. To a sub-project in directory A. However, in the master branch of the project the sub-project has moved to so a separate directory, directory B.
I have about 10 commits I want to effectively cherry-pick into master, but how can I tell git to put the old directory into the new one?
Later
I tried to cherry pick because I wanted to only introduce my changes and keep the history clean. It's not just file moves. I've also added new classes as well. It didn't detect all of the moves either.(the first file that comes to mind is pom.xml)
Upvotes: 3
Views: 2323
Reputation: 38762
You can convert these commits to patches, edit the patches manually (substituting old paths with new paths) and then apply.
$ git init
Initialized empty Git repository in /tmp/gitt/.git/
$ mkdir olddir
$ cp /home/vi/code/_/ucontext.cpp olddir/ucontext.cpp
$ git add .
$ git commit -m "initial commit"
[master (root-commit) c0bf371] initial commit
1 files changed, 97 insertions(+), 0 deletions(-)
create mode 100644 olddir/ucontext.cpp
$ printf '22\na\n// Sup, /git/!\n.\nw\nq\n' | ed olddir/ucontext.cpp
1983
if (!stacks) { stacks = stacks3; }
1998
$ git commit -am 'sample commit'
[master 83940c9] sample commit
1 files changed, 1 insertions(+), 0 deletions(-)
$ printf '33\nd\nw\nq\n' | ed olddir/ucontext.cpp
1998
}else{
1990
$ git commit -am 'sample commit 2'
[master 6599932] sample commit 2
1 files changed, 0 insertions(+), 1 deletions(-)
$ git format-patch HEAD~2 --stdout > saved-commites.patch
$ git reset --hard HEAD~2
HEAD is now at c0bf371 initial commit
$ git mv olddir newdir
$ git commit -m 'rename dir'
[master bd8a77e] rename dir
1 files changed, 0 insertions(+), 0 deletions(-)
rename {olddir => newdir}/ucontext.cpp (100%)
$ sed -i.bak 's!\([ab]/\)olddir/!\1newdir/!g' saved-commites.patch
$ git am saved-commites.patch
Applying: sample commit
Applying: sample commit 2
Upvotes: 4