git: be9db83332 - main - git primer: Update info about rebasing in a few places

From: Warner Losh <imp_at_FreeBSD.org>
Date: Wed, 25 Jun 2025 15:32:06 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/doc/commit/?id=be9db83332da2904403179527cb829628f13113a

commit be9db83332da2904403179527cb829628f13113a
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2024-12-04 17:05:49 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2025-06-25 15:31:27 +0000

    git primer: Update info about rebasing in a few places
    
    Experience has shown that some of the advice in this primer is awkward
    and clunky. Address some of that by refining what we suggest.
    
    Sponsored by:           Netflix
---
 .../en/articles/committers-guide/_index.adoc       | 23 ++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/documentation/content/en/articles/committers-guide/_index.adoc b/documentation/content/en/articles/committers-guide/_index.adoc
index 90db1ecdf2..d52aab2ee5 100644
--- a/documentation/content/en/articles/committers-guide/_index.adoc
+++ b/documentation/content/en/articles/committers-guide/_index.adoc
@@ -1609,9 +1609,9 @@ The following answer assumes you committed to `main` and want to create a branch
 
 [source,shell]
 ....
-% git branch issue                # Create the 'issue' branch
-% git reset --hard freebsd/main   # Reset 'main' back to the official tip
-% git checkout issue              # Back to where you were
+% git checkout -b issue              # Create the 'issue' branch
+% git checkout -B main freebsd/main  # Reset main to upstream
+% git checkout issue                 # Back to where you were
 ....
 
 ===== Ooops! I committed something to the wrong branch!
@@ -1632,8 +1632,15 @@ It also assumes that it's the last commit on wilma (hence using wilma in the `gi
 % git reset --hard HEAD^	# move what wilma refers to back 1 commit
 ....
 
-Git experts would first rewind the wilma branch by 1 commit, switch over to fred and then use `git reflog` to see what that 1 deleted commit was and
-cherry-pick it over.
+If it is not the last commit, you can cherry-pick that one change from wilma onto fred, then use `git rebase -i` to remove the change from wilma.
+
+[source,shell]
+....
+# We're on branch wilma
+% git checkout fred			# move to fred branch
+% git cherry-pick HASH_OF_CHANGE	# copy the misplaced commit
+% git rebase -i main wilma		# drop the cherry-picked change
+....
 
 **Q:** But what if I want to commit a few changes to `main`, but keep the rest in `wilma` for some reason?
 
@@ -1748,6 +1755,8 @@ How do I recover?
 
 **A:** This can happen when you invoke the pull with your development branch checked out.
 
+Many developers use `git pull --rebase` to avoid this situation.
+
 Right after the pull, you will have the new merge commit checked out.
 Git supports a `HEAD^#` syntax to examine the parents of a merge commit:
 
@@ -1762,9 +1771,11 @@ Then you simply reset your branch to the corresponding `HEAD^#`:
 
 [source,shell]
 ....
-git reset --hard HEAD^2
+git reset --hard HEAD^1
 ....
 
+In addition, a `git pull --rebase` at this stage will rebase your changes to 'main' to the latest 'freebsd/main'.
+
 **Q:** But I also need to fix my `main` branch. How do I do that?
 
 **A:** Git keeps track of the remote repository branches in a `freebsd/` namespace.