Doc: Explain how to rebase and squash PR's commits

This commit is contained in:
Alan Carvalho de Assis 2022-12-18 18:00:35 -03:00 committed by Xiang Xiao
parent 4d2794250f
commit 9eea82a61d

View file

@ -211,6 +211,138 @@ squash before submitting the Pull Request:
happy, they may suggest squashing and merging again to make a single commit. In this case you would repeat steps
1 through 6.
How to Include the Suggestions on Your Pull Request?
----------------------------------------------------
If you submitted your first PR (Pull Request) and received some feedbacks
to modify your commit, then probably you already modified it and created a
new commit with these modifications and submitted it.
Also probably you saw that this new commit appeared on your Pull Request at
NuttX's github page (at Commits tab).
So, someone will ask you some enigmatic thing: "Please rebase and squash these commits!"
Basically what they are saying is that you need to update your repository
and fuse your commits in a single commit.
Let walk through the steps to do it!
Move to upstream branch and pull the new commits from there:
.. code-block:: bash
$ git checkout upstream
$ git pull
Return to your working branch and rebase it with upstream:
.. code-block:: bash
$ git checkout my-branch
$ git rebase upstream
If you run git log will see that your commits still there:
.. code-block:: bash
$ git log
commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (HEAD -> firstpr, upstream/master, upstream)
Author: Me Myself
Date: Today few seconds ago
Fix suggestions from mainline
commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Author: Me Myself
Date: Today few minutes ago
Initial support for something fantastic
commit 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date: Sun Dec 18 00:00:00 2022 +0800
Some existing commit from mainline
See, you have two commits (Fix suggestions... and Initial support...), we can squash both in a single commit!
You can use the git rebase interactive command to squash both commits:
.. code-block:: bash
$ git rebase -i HEAD~2
Note: case you had 3 commits, then you should replace HEAD~2 with HEAD~3 and so on.
This command will open the nano editor with this screen:
.. code-block:: bash
pick 10ef3900b2 Initial support for something fantastic
pick 9431582586 Fix suggestions from mainline
# Rebase 9b0e1659ea..9431582586 onto 9b0e1659ea (2 commands)
#
# Commands:
# p, pick <commit> = use commit
...
Here you can control the actions that git will execute over your commits.
Because we want to squash the second commit with the first you need to
replace the 'pick' of the second line with a 'squash' (or just a 's') this way:
.. code-block:: bash
pick 10ef3900b2 Initial support for something fantastic
squash 9431582586 Fix suggestions from mainline
# Rebase 9b0e1659ea..9431582586 onto 9b0e1659ea (2 commands)
#
# Commands:
# p, pick <commit> = use commit
...
Now just press `Ctrl + X` to save this modification. In the next screen you can edit your git
commit messages. After that press Ctrl + X again to save.
If you run git log again will see that now there is one a single commit:
.. code-block:: bash
$ git log
commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx (HEAD -> firstpr, upstream/master, upstream)
Author: Me Myself
Date: Right now baby, right now
Initial support for something fantastic
This commit includes the suggestions from mainline
commit 6aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date: Sun Dec 18 00:00:00 2022 +0800
Some existing commit from mainline
Just push forced this new commit to your repository:
.. code-block:: bash
$ git push -f
Now you can look at your PR at NuttX's github to confirm that
this squashed commit is there.
Git Resources
-------------