Search code examples
gitgerrit

what is the proper way to get another commit on Gerrit and merge it into my local project


My team is working with Gerrit. I don't know how to get some other commit to my local project.

For example, one of my colleague has pushed his own changes onto Gerrit but the changes hasn't been merged into the branch master. I can see his changes: enter image description here

Now, I have my own changes, which is still in my own PC, meaning that I haven't yet pushed my own changes onto Gerrit. What I need is to get his changes and merge it into my local changes.

Why? Because I need to compile the project with his changes and deploy the executable file on a testing server.

I know that Gerrit offered me some methods to fetch others' changes, such as checkout, cherry-pick, patch etc. But I don't know which one is the best for the case as below:

  • merge some other changes from Gerrit into my local project
  • recover my local project easily, meaning that abandon the merge and get back my local project

Solution

  • I'll suppose your local change is committed in a branch called "branch-1".

    Then, do the following procedure:

    Create a new branch based on the original one, to make your tests, and checkout it:

    git checkout -b branch-2 branch-1
    

    Bring all changes you want using the "Cherry Pick" download command available in the change pages on Gerrit:

    git fetch ... && git cherry-pick FETCH_HEAD <= Change 1
    git fetch ... && git cherry-pick FETCH_HEAD <= Change 2
    ...
    

    Compile and deploy

    When you're done just come back to the original branch:

    git checkout branch-1