共享(拉请求)只有一些提交上游存储库 [英] Share (pull request) ONLY SOME commits with upstream repository

查看:135
本文介绍了共享(拉请求)只有一些提交上游存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们面临的情况是,我们正在为我们公司(GA)定制Web应用程序,并需要通过请求发送对git上游回购的一些更改。上游的webapp是AUS。这些更改将在特定文件中进行,并且在工作完成之前已知。所有的工作(即使是AUS)都会在GA中被捕获。



我们如何在没有重复提交的情况下执行此操作(从 cherry-pick rebase )并保持整洁并易于遵循?

一个'配方'为这个,并希望分享它。

解决方案

我描述配方和显示存储库状态的屏幕截图如SourceTree所示(因为它一次显示所有分支)。请注意,这些分支是'au','ga'和'master',而不是配方中使用的GPT-99_description_AU,GPT-99_description_GA和GPT-99_description。

(你可能会问,为什么在每个代码块之前有一个额外的行和一段时间 - 这是我今天能够格式化的唯一方法!)


  1. 创建3个分支。他们应该反映正在进行的问题,并为AuScope和GA提供一个问题。我们还需要一个合并为



  $ git checkout master#或任何我们将使用的基本分支
$ git分支GPT-99_description
$ git分支GPT-99_description_AU
$ git分支GPT-99_description_GA




  1. 在GA分支上执行所有工作

  $ git checkout GPT-99_description_GA 




  1. 根据需要执行编辑,添加文件和删除文件
  2. 鉴别将要前往AUS的文件,因为它们必须单独提交(否则,我们将如何向AUS发送JUST THOSE提交?)
  3. 提交AUS文件。使用标识为AUS文件提交的内容开始提交消息



  $ git add< files> 
$ git commit -mGPT-99 - AUS files - ...

也许而不是使用消息使用标记。稍后再看。


  1. 提交GA文件。无需识别信息。



  $ git add< files> 
$ git commit -mGPT-99 - ...


  1. 切换到AuScope分支



    1.  切换到AuScope分支




      1. Cherry选择AuScope提交(查看日志)
      2. ol>

          $ git cherry-pick SHA#1 
        $ git cherry-pick SHA#2
        ...


        1. 现在发生的情况是,提交已被复制并存在GA和AUS分支上。提交是分开的(它们有不同的SHA),但它们的实质是相同的 - 如果两者都重播,将会有冲突,因为两者都会尝试添加/删除/编辑同一事物。我们可以使用


          1. 重复的提交现在被整合。然而GA分支没有AUS变化。为了做到这一点,我们合并:



            $ git checkout GPT-99_description_GA 
          $ git merge GPT-99_description_AU




          1. 存储库现在处于GA分支上的所有更改状态,并且打算作为AuScope的拉取请求发送的更改位于AU分支上。

          进行拉取请求

          We face a situation where we are customising a webapp for our company (GA) and need to send SOME changes to the git upstream repo via pull requests. The upstream webapp is "AUS". The changes will be in specific files and are known about before the work is done. All work (even for AUS) is to be captured in GA.

          How do we go about this without duplicate commits (from cherry-pick and rebase) and to keep it clean and easy to follow?

          I worked out a 'recipe' for this and wanted to share it.

          解决方案

          I describe the recipe and show screenshots of the state of the repository as seen by SourceTree (since it shows all branches at once). Note that the branches are 'au', 'ga' and 'master' instead of GPT-99_description_AU, GPT-99_description_GA and GPT-99_description as used in the recipe.

          (You may ask why there is an extra line and a period before each code block - the only way I could get it to format today!)

          1. Create 3 branches. They should reflect the issue being worked on and have one for AuScope and another for GA. We also need one to merge into

          .

          $ git checkout master # or whatever base branch we will be using
          $ git branch GPT-99_description
          $ git branch GPT-99_description_AU
          $ git branch GPT-99_description_GA
          

          1. Perform all work on the GA branch

          .

          $ git checkout GPT-99_description_GA
          

          1. Perform edits, add files and delete files as required
          2. IDENTIFY THE FILES THAT WILL GO TO AUS since they must be committed separately (otherwise how will we send JUST THOSE commits to AUS?)
          3. Commit the AUS files. Start the commit message with something that identifies as AUS file commits

          .

          $ git add <files>
          $ git commit -m "GPT-99 - AUS files - ..." 
          

          Perhaps instead of using a message use tagging. Something to look at later.

          1. Commit the GA files. No need for an identifying message.

          .

          $ git add <files>
          $ git commit -m "GPT-99 - ..."
          

          1. Switch to the AuScope branch

          .

          Switch to the AuScope branch
          

          1. Cherry pick the AuScope commits (look at the log)

          .

          $ git cherry-pick SHA#1
          $ git cherry-pick SHA#2
          ...
          

          1. Now what has happened here is that the commits have been copied and will exist on the GA an AUS branches. The commits are separate (they have different SHAs) but their substance is the same - if both are replayed there will be a conflict as both will be trying to add/delete/edit the same thing. We can use a git trick as described at https://git-scm.com/book/en/v2/Git-Branching-Rebasing#Rebase-When-You-Rebase, where the copied commits will have a patch-id that identifies the commits as being the same. This allows us to rebase and git will resolve the different commits to be just one

          .

          $ git rebase --onto GPT-99_description GPT-99_description_AU GPT-99_description_GA
          

          1. The duplicate commits are consolidated now. However the GA branch is without the AUS changes. To make this happen we merge:

          .

          $ git checkout GPT-99_description_GA
          $ git merge GPT-99_description_AU
          

          1. The repository is now in the state where ALL changes are on the GA branch and the changes that are intended to be sent as a pull request to AuScope are on the AU branch.

          这篇关于共享(拉请求)只有一些提交上游存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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