从目录A到目录B的Git Cherry Pick文件 [英] Git cherry pick files, from Directory A to Directory B

查看:195
本文介绍了从目录A到目录B的Git Cherry Pick文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在进行一些实验性更改的项目.移至目录A中的子项目.但是,在项目的主分支中,子项目已移至一个单独的目录,即目录B.

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.

我有大约10个提交要有效地挑选到master中,但是如何告诉git将旧目录放入新目录中呢?

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?

稍后
我之所以选择樱桃,是因为我只想介绍我的更改并保持历史记录整洁.不只是文件移动.我还添加了新类.它也没有检测到所有移动.(想到的第一个文件是pom.xml)

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)

推荐答案

您可以将这些提交转换为补丁,手动编辑补丁(用新路径替换旧路径),然后应用.

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

这篇关于从目录A到目录B的Git Cherry Pick文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆