@@ -133,5 +133,49 @@ git rebase --continue
133133
134134### How do I clean up my git history?
135135
136- TODO: Link to a beginner-friendly external resource, or (less preferably)
137- describe basic usage of rebase here.
136+ Git's history can sometimes become cluttered with many small commits.
137+ Fortunately, Git has a feature called ` rebase ` that allows you to clean up your commit history.
138+ If you want to learn more,
139+ [ GitHub - About Git rebase] ( https://docs.github.com/en/get-started/using-git/about-git-rebase )
140+ provides a comprehensive overview of ` rebase ` .
141+
142+ > ** Warning**
143+ We suggest considering to ` rebase ` only those commits that haven't been pushed to a public branch.
144+ Rebasing existing commits would block merging because we don't allow force pushes to the repository.
145+ If you need to tidy up commits that have already been pushed,
146+ it's generally better to use ` git revert ` for the sake of avoid causing confusion for other developers.
147+
148+
149+ Here's a small gist that goes through the basics on how to use it:
150+
151+ 1 . Begin an interactive rebase: Use ` git rebase -i HEAD~N ` , where ` N ` is the number of commits
152+ from the latest one you want to edit. This will open a text editor,
153+ listing the last ` N ` commits with the word "pick" next to each one.
154+
155+ ``` sh
156+ git rebase -i HEAD~N
157+ ```
158+
159+ 2 . Edit the commits: Replace "pick" with the operation you want to perform on the commit:
160+
161+ - ` reword ` : Change the commit message.
162+ - ` edit ` : Amend the commit.
163+ - ` squash ` : Combine the commit with the previous one.
164+ - ` fixup ` : Similar to ` squash ` , but discard this commit's log message.
165+ - ` drop ` : Remove the commit.
166+
167+ 3 . Save and exit: After saving and closing the file, git will execute each operation.
168+ If you selected ` reword ` , ` edit ` , or ` squash ` , git will pause and give you a chance
169+ to alter the commit message or the commit itself.
170+
171+ ``` sh
172+ git commit --amend
173+ ```
174+
175+ 4 . Continue the rebase: Once you're done with each commit, you can continue the rebase
176+ using ` git rebase --continue ` . If you want to abort the rebase at any point,
177+ you can use ` git rebase --abort ` .
178+
179+ ``` sh
180+ git rebase --continue
181+ ```
0 commit comments