Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a pull request of a single commit on github

Tags:

git

github

I see that similar questions have been asked many times, but I still don't understand and I need a practical example for my case.

I have a github repo with two branches:

  1. master which is my development branch and where I want to push all latest changes and new features
  2. stable where I want to push bug fixings only until new features have been tested.

Now I have made 4 commits and pushed them to master. First three commits are new features, last commit is a bug fixing.

In github, if I select stable branch, it shows that it is 4 commits behind master (which is correct).

Now I want last commit only to be pushed to stable branch. How do I achieve that?

like image 851
lviggiani Avatar asked Mar 10 '23 00:03

lviggiani


2 Answers

You can cherry-pick the last-commit-hash in your stable branch and push to remote.

$ git fetch
$ git log                               # copy the last-commit-hash 

$ git checkout -b stable origin/stable  # create local/stable branch from remote/stable
$ git cherry-pick <last-commit-hash>    # take the last-commit
$ git push origin HEAD                  # update remote/stable
like image 93
Sajib Khan Avatar answered Mar 14 '23 06:03

Sajib Khan


Solution:

You can use git cherry-pick to apply a single commit by itself to your current branch.

git checkout stable
git cherry-pick <last_commit_id>

Background:

git cherry-pick will apply the changes made in an existing commit to another branch, while recording a new commit. Essentially, you can copy commits from branch to branch.

Given the following tree

dd2e86 - 946992 - 9143a9 - a6fd86 - 5a6057 [master]
           \
            76cada - 62ecb3 - b886a0 [feature]

Let's say we want to copy b886a0 to master (on top of 5a6057).

We can run

git checkout master
git cherry-pick b886a0
Now our tree will look something like:

dd2e86 - 946992 - 9143a9 - a6fd86 - 5a6057 - a66b23 [master]
           \
            76cada - 62ecb3 - b886a0 [feature]
like image 31
Avinash Avatar answered Mar 14 '23 06:03

Avinash