Share (pull request) ONLY SOME commits with upstream repository

浪尽此生 提交于 2019-12-24 05:30:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/32600066/share-pull-request-only-some-commits-with-upstream-repository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!