Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| docs:guide-developer:working-with-github-pr [2019/03/23 15:21] – added squashing commits bobafetthotmail | docs:guide-developer:working-with-github-pr [2023/03/18 23:29] (current) – [Reopen closed PR] he/she -> they ryanc | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ===== Working with Github | + | ====== Working with GitHub ====== |
| + | There are GitHub mirrors of the source repository [[https:// | ||
| - | There are Github mirrors of the source repository [[https:// | + | Fork the project to a public repo using GitHub |
| - | Fork the project to a public repo using Github | + | |
| - | In case you don't know how to do that, keep reading.\\ | + | In case you don't know how to do that, keep reading. |
| - | Create a Github | + | Create a GitHub |
| - | Install git in your PC, and make sure that your local git settings have the right name and email\\ | + | Install git in your PC, and make sure that your local git settings have the right name and email: |
| - | < | + | |
| + | < | ||
| git config --global user.name "my name" | git config --global user.name "my name" | ||
| git config --global user.email " | git config --global user.email " | ||
| </ | </ | ||
| - | You might also want to set the default text editor to your favourite | + | You might also want to set the default text editor to your favorite |
| - | If you have a Linux system with a GUI, some choices are **geany**, **kwrite**, **pluma** and **gedit**.\\ | + | If you have a Linux system with a GUI, some choices are **geany**, **kwrite**, **pluma** and **gedit**. |
| - | If you are using command line, **nano** is a good one. < | + | If you are using command line, **nano** is a good one. |
| - | Then follow Github' | + | <code bash> |
| + | git config | ||
| + | </code> | ||
| - | After you have set it up as described, write < | + | Then follow GitHub' |
| - | All commits you do after this command will be grouped in this branch. This allows to have multiple branches, one for each PR.\\ | + | |
| - | To switch between branches you already created, use < | + | |
| - | After you made your changes, write < | + | After you have set it up as described, write |
| - | Then write < | + | < |
| - | The first line is the commit subject, \\ | + | git checkout |
| - | then leave an empty line \\ | + | </code> |
| - | then you write the commit description. \\ | + | |
| - | This command will automatically add the Signed-off-by line with your name and email as set above.\\ | + | |
| - | For example, a complete commit message might look like this:\\ | + | |
| - | The best code update. | + | |
| - | + | ||
| - | This is the best piece of code I have ever submitted. | + | |
| - | Signed-off-by: | + | |
| - | To send your local changes over to your Github repo, write < | + | to create a branch for your PR ("my-new-branch-name" |
| - | You will be asked your github user and password | + | |
| - | After the code has been uploaded | + | All commits you do after this command will be grouped in this branch. |
| + | This allows | ||
| + | To switch between branches you already created, use | ||
| + | <code bash> | ||
| + | git checkout my-branch-name | ||
| + | </ | ||
| + | |||
| + | After you made your changes, write | ||
| + | |||
| + | <code bash> | ||
| + | git add -i | ||
| + | </ | ||
| + | |||
| + | and use its interface to add untracked (new) files and update existing ones. | ||
| + | |||
| + | Then write | ||
| + | <code bash> | ||
| + | git commit --signoff | ||
| + | </ | ||
| + | |||
| + | This will open the git default editor and you can write the commit message. | ||
| + | |||
| + | The first line is the commit subject, then leave an empty line, then you write the commit description. | ||
| + | This command will automatically add the Signed-off-by line with your name and email as set above. | ||
| + | For example, a complete commit message might look like this: | ||
| + | |||
| + | <code bash> | ||
| + | The best code update. | ||
| + | |||
| + | This is the best piece of code I have ever submitted. | ||
| + | Signed-off-by: | ||
| + | </ | ||
| + | |||
| + | To send your local changes over to your GitHub repo, write | ||
| + | |||
| + | <code bash> | ||
| + | git push --all | ||
| + | </ | ||
| + | |||
| + | You will be asked your GitHub user and password in the process. | ||
| + | |||
| + | After the code has been uploaded to your GitHub repo, you can submit pull request using GitHub web interface, see again GitHub' | ||
| ===== Squashing commits ===== | ===== Squashing commits ===== | ||
| - | Commits in a PR or sent by email should be about full changes you want to merge, not about fixing all issues the reviewers found in your original PR.\\ | + | Commits in a PR or sent by email should be about full changes you want to merge, not about fixing all issues the reviewers found in your original PR. |
| So, there will come a time when you will need to either rewrite or squash your commits; so you end with a normal amount of true and sane commits. | So, there will come a time when you will need to either rewrite or squash your commits; so you end with a normal amount of true and sane commits. | ||
| - | Work with git commandline.\\ | + | Work with git commandline. |
| - | Change to your development folder.\\ | + | Change to your development folder. |
| - | Look at the branches you have with: < | + | Look at the branches you have with: |
| - | get something like:< | + | |
| + | < | ||
| + | git branch -a | ||
| + | </ | ||
| + | |||
| + | get something like: | ||
| + | |||
| + | < | ||
| best_code_update | best_code_update | ||
| - | * master</ | + | * master |
| + | </ | ||
| - | Switch to the your development branch for this PR with:< | + | Switch to the your development branch for this PR with: |
| - | Look at the git log, so you can count the number of commits you want to squash ( the " | + | <code bash> |
| + | git checkout best_code_update | ||
| + | </ | ||
| + | |||
| + | Look at the git log, so you can count the number of commits you want to squash ( the " | ||
| + | |||
| + | < | ||
| + | git log | ||
| + | </ | ||
| + | |||
| + | Delete commits with: | ||
| + | |||
| + | <code bash> | ||
| + | git reset HEAD~X | ||
| + | </ | ||
| + | |||
| + | (where X is the number of commits you want to delete, counted from the last commit), this will not change modified files, it will only delete the commits. | ||
| + | |||
| + | Add the files to git tracking again with: | ||
| + | |||
| + | <code bash> | ||
| + | git add -i | ||
| + | </ | ||
| + | |||
| + | and commit again with: | ||
| + | |||
| + | <code bash> | ||
| + | git commit --signoff | ||
| + | </ | ||
| + | |||
| + | Send the updated branch over to GitHub with: | ||
| + | |||
| + | <code bash> | ||
| + | git push -f | ||
| + | </ | ||
| - | Delete commits with:< | ||
| - | (where X is the number of commits you want to delete, counted from the last commit), this will not change modified files, it will only delete the commits.\\ | ||
| - | Add the files to git tracking again with:< | ||
| - | and commit again with:< | ||
| - | Send the updated branch over to github with: < | ||
| and the commits in the PR will be updated automatically. | and the commits in the PR will be updated automatically. | ||
| - | ==== Alternative squashing advice: ==== | + | ==== Alternative squashing advice ==== |
| + | You can use **interactive rebase** to combine, reorder and edit your commits and their commit messages, with: | ||
| - | You can use **interactive rebase** to combine, reorder and edit your commits and their commit messages, with:< | + | < |
| + | git rebase -i HEAD~X | ||
| + | </ | ||
| + | |||
| + | Where X is a number of commits to edit. | ||
| + | |||
| + | |||
| + | ===== Reopen closed PR ===== | ||
| + | |||
| + | GitHub will grey out " | ||
| + | |||
| + | However, reopening is still possible if you just set back the GitHub branch to the exact commit ID/hash it was at when you closed it. This even works when the branch or even the whole repository was deleted on GitHub. It just has to be recreated with the same name (for repo and branch) and the same commit hash at the branches HEAD. | ||
| + | |||
| + | A possible way to do that would be (there might be others, even shorter ones): | ||
| + | |||
| + | //We assume that the git remote referring to GitHub is called " | ||
| + | |||
| + | <code bash> | ||
| + | # Get the hash yyyyyyyyyyyyyyy of the current state of " | ||
| + | git log -1 testbranch | ||
| + | # Checkout the latest state of the PR (commit hash xxxxxxxxxxx) | ||
| + | git checkout xxxxxxxxxx | ||
| + | # Delete old testbranch | ||
| + | git branch -D testbranch | ||
| + | # Label current state as testbranch | ||
| + | git checkout -b testbranch | ||
| + | # Push old state to GitHub | ||
| + | git push -f origin testbranch | ||
| + | </ | ||
| + | |||
| + | |||
| + | Now you got GitHub at the state it was at when closing the PR. It should now be possible to " | ||
| + | Note that this will only be possible if //you// closed it. If it was closed by an admin, you will have to ask an admin to reopen it (though they will also only be able to do that when the branch is at the proper hash). | ||
| + | If the PR is reopened, you can update as usual, e.g. | ||
| + | |||
| + | <code bash> | ||
| + | # Checkout the desired hash yyyyyyyyy (or branch) | ||
| + | git checkout yyyyyyyyy | ||
| + | # Delete intermediate testbranch | ||
| + | git branch -D testbranch | ||
| + | # Label current state as testbranch | ||
| + | git checkout -b testbranch | ||
| + | # Push new state to GitHub | ||
| + | git push -f origin testbranch | ||
| + | </ | ||