Often when you work with other developers the question arises: "How to push a commit into someone's patch set with git" or "How to create a patch set in other user's patch"? Let's go through the whole process step by step.
-
Check all our changed files that we are going to push using the command:
git status -
Add them to the staging area:
git add <path>Where instead of
<path>you should provide the full path to the file. Or you can usegit add .to add all changed files at once. -
Save your commit as part of the shared patch:
git commit --amendThen press
Ctrl+O(Save) andCtrl+X(Exit). -
Push the commit to the server:
git push origin HEAD:refs/changes/<number>Where instead of
<number>you should substitute the number of the main patch into which you are pushing. You can see it in Github or wherever you fetched the patch you now want to push your commit to. For example, the main patch in Gerrit might look likegerrit.ourproject.com/#/c/2715.So we need to replace 2715 and get:
git push origin HEAD:refs/changes/2715
Press Enter and that's it – your commit has been sent to the server. If you have any remaining questions, post them in the comments.