morris295
morris295

Reputation: 547

Git only merging some commits

Let's say that I have a git repository containing the following branches:

On the QA branch I have commit 'A' which has been approved for release, I also have commit 'B' that has not been approved for release.

Is there a way for me to merge only up to commit 'A' into staging and master so that the changes not approved for release are kept out of the staging/production environments?

Upvotes: 1

Views: 162

Answers (2)

Schwern
Schwern

Reputation: 164759

On the QA branch I have commit 'A' which has been approved for release, I also have commit 'B' that has not been approved for release. Is there a way for me to merge only up to commit 'A' into staging and master so that the changes not approved for release are kept out of the staging/production environments?

What you're asking for demonstrates a problem with managing releases with branches: you can only have one thing in QA at a time, and they tend to pile up. A lot of complexity can be avoided if you use the feature branch workflow and do QA and staging with tags instead of branches.

Now, to fix it in your current workflow...

You can make a feature branch off B, move QA to A, deal with QA (now at A) normally, and work on B as normal.

Here's your repo, presumably.

Z - A - B [QA]
 \
  C - D [staging]
       \
        E - F [master]
  1. Make a feature branch off B...
$ git branch feature/B B

      [feature/B]
Z - A - B [QA]
 \
  C - D [staging]
       \
        E - F [master]
  1. Move QA back to A.
$ git checkout QA
$ git reset --hard A
$ git push --force-with-lease

      B [feature/B]
     /
Z - A [QA]
 \
  C - D [staging]
       \
        E - F [master]
  1. Release QA as normal.
  2. Continue developing the feature.

Upvotes: 1

matt
matt

Reputation: 534977

The "object" of a git merge command is always a commit. (The fact that you usually say the name of a branch is merely a contingent fact, because a branch just happens to be another name for a commit.) So, using the SHA for the commit you want to merge "only up to", just merge it.

Upvotes: 1

Related Questions