0

I've setup Gitlab and I'm trying to follow the workflow mentioned here: Gitlab Production branch flow.

Now my repository looks like this:

enter image description here

And I've been asked to merge only commit A of the master branch with the production branch. What is the best way to do this?

Should I use the git cherry-pick command? I read I'll loose the version history with the cherry-pick.

If I've this situation where I need to keep merging one of the previous commits from master branch to the production branch, how do I handle this?

I'm stuck at this. Any help is greatly appreciated.

Thanks,

Update: From master branch I can push only specific commits: git push <remotename> <commit SHA>:<remotebranchname>

Found answer here: How can I push a specific commit to a remote, and not previous commits?

Raghavendra N
  • 1,359
  • 1
  • 18
  • 36
  • is there anything between A and X? – max630 Oct 29 '16 at 17:49
  • Nothing. x is the latest commit merged to the production branch and is deployed to the production server. Actually in my repository commit A represents a small feature. It was completed but did not get pushed to production and I continued work on other features. Now I only want to push the feature A to the production. – Raghavendra N Oct 30 '16 at 08:23
  • then you can simply merge the A commit. Actually, the given answer suggests just this. – max630 Oct 30 '16 at 08:37
  • `cherry-pick`? I wanted to avoid this. I found another approach: `git checkout -b branch_x commit_hash`. And then I can merge the **branch_x** with the production and delete **branch_x**. Am I doing it right? – Raghavendra N Oct 30 '16 at 08:45
  • Possible duplicate of [Merge up to a specific commit](https://stackoverflow.com/questions/8223103/merge-up-to-a-specific-commit) – Basix Feb 06 '18 at 18:45

1 Answers1

1

Cherry picking is viable if you specifically want the changes made in select commits. It's most beneficial when the commits you need to apply didn't occur in sequential order. Personally, I wouldn't recommend you do this on master/production branches as it's not a good long term release strategy.

My advice is based on git flow, which I know is somewhat different to GitLab's approach.

If these are actual releases, consider following a release branch workflow, where in this case you create a release branch on commit A, and then merge into production.

If these are bugfix/hotfixes needing some commits but not all (requiring cherry-picking), you could create a hotfix branch from your production branch, cherry-pick the commit you need to that branch first, then when testing is finalized merge that back into production. If any extra changes or commits are applied in that branch they will need to be merged back into whatever your development branch is as well.

Flowers4Life
  • 151
  • 5