How can I save a commit from branch A into branch B?

Advertisements

I have 3 different branches: production, development and staging. We are currently using the development branch to merge our code. However, in the last commit in development branch the build has failed. The successfully build is in the previous commit. How can I store the development commit that was successfully build into the staging branch?

This is what I’m trying to do:

  1. git checkout staging
  2. git checkout -b
    staging-with-successfully-commit-from-development-branch
  3. git cherry-pick my-hash-commit

But when I do that I can’t install the dependencies because I don’t have a package.json.
Is there another way of doing that?

>Solution :

I think you want to point your staging branch to the "last good commit". In that case:

First make sure you have no pending changes that you want to keep. Save them in a commit or stash. Then:

git checkout staging
git reset --hard <the-good-commit>
git push

This means:

  • git checkout staging: go to the staging branch
  • git reset --hard <the-good-commit>: make the staging branch point to . The --hard option indicates that you want all your current files to be changed as well to have the exact contents of . If you had any uncommitted changes, they will be lost forever. Depending on your workflow you can also use git merge or git rebase.
  • git push: push the new version of the release branch to the remote server.

Leave a Reply Cancel reply