git樱桃选择或合并来自另一个分支的特定目录 [英] git cherry-pick or merge specific directory from another branch

查看:115
本文介绍了git樱桃选择或合并来自另一个分支的特定目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在StackOverflow上看到过不同的帖子,它解释了樱桃采摘的一些问题,但是他们代码中的注释并不是关于什么是分支和什么是目录的具体细节。例子 git checkout A - XY 不会告诉我很多。



基本上我想要这个:

>


  • 创建新分支 featureA 关闭 master / tools / my-tool 来自分支 dev 中的
  • into featureA


解决方案

关于如何挑选一些目录(作为提交而不是强力结账)的原始问题,这是可能的。想象一下, featureA 已经从 master 发散,并且您想要将 tools / my-工具提交。


假设您从未做过任何提交,其中包含 / tools / my-tool 以及其他目录中的内容


这会向您提供提交列表 master 位于 tools / my-tool 中(不在 featureA
pre $ g $ git log --no-merges featureA ... master tools / my $ gt; $ gt; $ gt; $ c>),按照反向时间顺序排列:

-tool

用另一种方式说:

  git log --no-merges source_branch ... dest_branch my / firstpath my / secondpath [...] 

要按照时间顺序获取所需的提交,首先需要反转输入行的顺序(例如使用 tail -r tac ),然后隔离com的列(如 cut ):

  git log  - format = oneline --no-merges featureA ... master tools / my-tool \ 
| tail -r \
| cut -d-f 1

要一次完成整个操作,请执行以下操作:

  git cherry-pick $(git log --format = oneline --no-merges featureA ... master tools / my- tool | tail -r | cut -d-f 1)


I've seen different posts on StackOverflow that explain cherry picking a bit, but the comments in their code aren't very specific as to what's a branch and what's a directory. Example git checkout A -- X Y doesn't tell me much.

Basically I want this:

  • Create new branch featureA off of master
  • Merge directory /tools/my-tool from branch dev into featureA

解决方案

To answer the original question about how to cherry-pick some directories (as commits instead of a brute-force checkout), this is possible. Imagine that featureA has diverged from master and you want to bring over the tools/my-tool commits.

Assuming that you never made any commits that contain both stuff from /tools/my-tool and stuff from other directories

This will get you the list of commits to master in tools/my-tool (that are not already in featureA), in reverse-chronological order:

git log --no-merges featureA...master tools/my-tool

To say it another way:

git log --no-merges source_branch...dest_branch my/firstpath my/secondpath [...]

To get just the commits you need in chronological order, you need to first reverse the order of the input lines (such as with tail -r or tac), then isolate the column for the commit hash (such as with cut):

git log --format=oneline --no-merges featureA...master tools/my-tool \
    | tail -r \
    | cut -d " " -f 1

And to do the whole operation at once, do this:

git cherry-pick $(git log --format=oneline --no-merges featureA...master tools/my-tool | tail -r | cut -d " " -f 1)

这篇关于git樱桃选择或合并来自另一个分支的特定目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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