How to merge a specific commit in Git

后端 未结 7 1428
攒了一身酷
攒了一身酷 2020-11-22 01:41

I have forked a branch from a repository in GitHub and committed something specific to me. Now I found the original repository had a good feature which was at HEAD

7条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 01:56

    In my use case we had a similar need for CI CD. We used git flow with develop and master branches. Developers are free to merge their changes directly to develop or via a pull request from a feature branch. However to master we merge only the stable commits from the develop branch in an automated way via Jenkins.

    In this case doing cherry-pick is not a good option. However we create a local-branch from the commit-id then merge that local-branch to master and perform mvn clean verify(we use maven). If success then release production version artifact to nexus using maven release plugin with localCheckout=true option and pushChanges=false. Finally when everything is success then push the changes and tag to origin.

    A sample code snippet:

    Assuming you are on master if done manually. However on jenkins, when you checkout the repo you will be on the default branch(master if configured).

    git pull  // Just to pull any changes.
    git branch local-   // Create a branch from the given commit-id
    git merge local-  // Merge that local branch to master.
    mvn clean verify   // Verify if the code is build able
    mvn  release:clean release:prepare release:perform // Release artifacts
    git push origin/master  // Push the local changes performed above to origin.
    git push origin   // Push the tag to origin
    

    This will give you a full control with a fearless merge or conflict hell.

    Feel free to advise in case there is any better option.

提交回复
热议问题