Skip to content

Done a to-do of FAQ.md #66538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 46 additions & 2 deletions docs/HowToGuides/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,49 @@ git rebase --continue

### How do I clean up my git history?

TODO: Link to a beginner-friendly external resource, or (less preferably)
describe basic usage of rebase here.
Git's history can sometimes become cluttered with many small commits.
Fortunately, Git has a feature called `rebase` that allows you to clean up your commit history.
If you want to learn more,
[GitHub - About Git rebase](https://docs.github.com/en/get-started/using-git/about-git-rebase)
provides a comprehensive overview of `rebase`.

> **Warning**
We suggest considering to `rebase` only those commits that haven't been pushed to a public branch.
Rebasing existing commits would block merging because we don't allow force pushes to the repository.
If you need to tidy up commits that have already been pushed,
it's generally better to use `git revert` for the sake of avoid causing confusion for other developers.


Here's a small gist that goes through the basics on how to use it:

1. Begin an interactive rebase: Use `git rebase -i HEAD~N`, where `N` is the number of commits
from the latest one you want to edit. This will open a text editor,
listing the last `N` commits with the word "pick" next to each one.

```sh
git rebase -i HEAD~N
```

2. Edit the commits: Replace "pick" with the operation you want to perform on the commit:

- `reword`: Change the commit message.
- `edit`: Amend the commit.
- `squash`: Combine the commit with the previous one.
- `fixup`: Similar to `squash`, but discard this commit's log message.
- `drop`: Remove the commit.

3. Save and exit: After saving and closing the file, git will execute each operation.
If you selected `reword`, `edit`, or `squash`, git will pause and give you a chance
to alter the commit message or the commit itself.

```sh
git commit --amend
```

4. Continue the rebase: Once you're done with each commit, you can continue the rebase
using `git rebase --continue`. If you want to abort the rebase at any point,
you can use `git rebase --abort`.

```sh
git rebase --continue
```