Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Find the commit you want to backport.
    • Browsing GitHub is the easiest method. e.g. This commit on master is what I want.
    • The command line way is fairly easy as well. This command will show the last 3 commits on master:

      Code Block
      
      git checkout master
      git clean -df
      git pull --rebase upstream master
      git log -3
      

      'git clean -df' is an optional command which removes all untracked files which are left over from the previously checked out branch. This command is a good habit, because it helps to avoid accidentally adding such files to the index with 'git add -A'.

  2. The commit hash we want is efe907df91596c3eff4cc2eb80ee2bbe09d1f373. (We can shorten this and use just efe907. -x means "add some text pointing to the original commit")

    Code Block
    
    git checkout 1.9.x
    git clean -df
    git pull --rebase upstream 1.9.x
    git cherry-pick -x efe907
    git push upstream 1.9.x
    

...

Note: if the commit that you tried to cherry-pick was a merge commit, you may get an error message like:

Code Block

git cherry-pick -x de7fd1bd259ebb7ab95eb18659cbb19fd680cd3e
fatal: Commit de7fd1bd259ebb7ab95eb18659cbb19fd680cd3e is a merge but no -m option was given.

...

Code Block
git cherry-pick -x de7fd1bd259ebb7ab95eb18659cbb19fd680cd3e -m 1

When cherry picking, you may some times get this error: fatal: bad object xxxxxxxxxxxxxxxxx, where the x stand for the commit hash.

You need to fetch the latest changes from upstream master so that the commit you want to cherry-pick is in your local repo. "git fetch --all" should do the trick.

For instance, i got the above error when cherry picking some master commits into the 1.11.x branch. Switching back to the master branch, then do git pull --rebase upstream master, before switching back to the 1.11.x branch to try again, is all i needed.