GIT Cherry选择我在一个分支中存在的所有提交到另一个分支

时间:2018-07-20 07:51:29

标签: git cherry-pick git-cherry-pick

我有2个分支A和B。分支B有时是从分支A分支出来的,并且多个用户正在向这两个分支提交。我想从分支B到分支A挑选我所有的提交(分支A中尚不存在),而无需手动搜索每个提交。 有可能吗?

谢谢

2 个答案:

答案 0 :(得分:3)

更直接的方法是使用 rebase --onto

OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.interceptors().add(new Interceptor() {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response response = null;
        boolean responseOK = false;
        int tryCount = 0;

        while (!responseOK && tryCount < 3) {
            try {
                 SystemClock.sleep(3000);
                 response = chain.proceed(request);
                 responseOK = response.isSuccessful();                  
            }catch (Exception e){
                 Log.d("intercept", "Request is not successful - " + tryCount);                     
            }finally{
                 tryCount++;      
            }
        }

        // otherwise just pass the original response on
        return response;
    }
});

如果您的仓库看起来像这样:

git rebase --onto target-branch [LAST_COMMON_COMMIT_BEFORE_BRANCH] branch-to-move

命令

a - B - c - d - e -> master
      \      \
       \      f - g -> some-feature
        \
         h - i - j -> branch-to-move

将导致

git rebase --onto some-feature B branch-to-move

答案 1 :(得分:0)

弄清楚并制作了以下PowerShell脚本:

$Source = Read-Host -Prompt 'Enter Source branch: '
$Target = Read-Host -Prompt 'Enter Target branch: '
cd C:\project
git log $Source --not $Target --cherry --author=my@ema.il --author-date-order --reverse | 
Select-String -Pattern "commit" |
ForEach-Object { git cherry-pick -x $_.ToString().split("+")[-1].Trim(' ') }