Skip to content

Commit b1e58cf

Browse files
authored
Update FAQ.md
1 parent 330af0b commit b1e58cf

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

docs/HowToGuides/FAQ.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,44 @@ 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+
Here's a simple way to use it, 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+
1. Begin an interactive rebase: Use `git rebase -i HEAD~N`, where `N` is the number of commits
143+
from the latest one you want to edit. This will open a text editor,
144+
listing the last `N` commits with the word "pick" next to each one.
145+
146+
```sh
147+
git rebase -i HEAD~N
148+
```
149+
150+
2. Edit the commits: Replace "pick" with the operation you want to perform on the commit:
151+
152+
- `reword`: Change the commit message.
153+
- `edit`: Amend the commit.
154+
- `squash`: Combine the commit with the previous one.
155+
- `fixup`: Similar to `squash`, but discard this commit's log message.
156+
- `drop`: Remove the commit.
157+
158+
3. Save and exit: After saving and closing the file, git will execute each operation.
159+
If you selected `reword`, `edit`, or `squash`, git will pause and give you a chance
160+
to alter the commit message or the commit itself.
161+
162+
```sh
163+
git commit --amend
164+
```
165+
166+
4. Continue the rebase: Once you're done with each commit, you can continue the rebase
167+
using `git rebase --continue`. If you want to abort the rebase at any point,
168+
you can use `git rebase --abort`.
169+
170+
```sh
171+
git rebase --continue
172+
```
173+
174+
It's important to note that you should only rebase commits that have not been pushed to a public branch.
175+
If you need to tidy up commits that have already been pushed,
176+
it's generally better to use git revert to avoid causing confusion for other developers.

0 commit comments

Comments
 (0)