-1

I have two branches in the GIT GUI - Development and Production. When code is pushed onto development, in the CLI, I do git pull and then git merge and git push on the production branch.

If I have 3 commits on the CLI on development branch:

Commit1 - COMMIT HASH 1 Commit2 - COMMIT HASH 2 Commit3 - COMMIT HASH 3

How can I merge only Commit3 and Commit1 without using any additional branch?

Karan Saxena
  • 49
  • 12
  • As you said yourself, you can cherry pick. Unclear what the question is, or what "git pull and then git merge and git push on the production branch" even means. – matt May 25 '22 at 12:55
  • There are multiple things you *can* do here. However, what you *should* do depends on what your `development` branch represents. If your normal workflow is to merge `development` into `production` when you release something, then you probably don't want to have the branches diverged permanently. Do you ever want to release commit2 sometime in the future? – TTT May 25 '22 at 14:46

1 Answers1

2

Via a terminal, checkout the branch you want to apply the commits to with

git checkout <branchname>

then simply use

git cherry-pick <commit1hash>
git cherry-pick <commit3hash>

If you want to be sure of what you're doing, checkout a new branch from the branch you want to apply the commits to so you can also use it as a sandbox without messing with the code of your production branch.

Abdul Mateen
  • 1,418
  • 1
  • 14
  • 32
Slth
  • 105
  • 7