Skip to content

Commit

Permalink
docs: update instructions to update old email (tldr-pages#7509)
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Dec 16, 2021
1 parent df01173 commit 6eb7f71
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions contributing-guides/git-terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,25 @@ git push --force-with-lease

# Changing the email of any commit(s)

Let's take this commit history as an example:
1. Perform an [interactive rebase](https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt--i) specifying the reference of the earliest commit to modify as the argument. For example, if the earlist commit with the wrong email address was 6 commits ago, you can specify the commit hash or just `HEAD~6`.

| Commit Hash | Author Email
|---|---
| A | wrong@example.org
| B | correct@example.org
| C | correct@example.org
| D | wrong@example.org
| E | correct@example.org
| F (HEAD) | correct@example.org
```bash
git rebase --interactive HEAD~6
```

2. You'll see a list of commits starting from the referenced commit to `HEAD`. All of them will default to the instruction `pick`, this means use the commit as-is when replaying them. For the commits you want to edit, replace the word `pick` for `edit`, then save and exit the editor.

3. The branch will rewind to the referenced commit, then replay them until it reaches a commit with the `edit` instruction. Amend the commit for the correct email address, then continue rebasing. Repeat this step until you've succesfully finishing rebasing and replayed all commits.

To change the email of commits A and D, run
```bash
git commit --amend --author "Your Name <correct@example.org>"
git rebase --continue
```

4. Finally, because you modified the branch history, you'll need to force push back to your remote repository.

```bash
git reset A
git commit --amend --author="Your Name <correct@example.org>"
git cherry-pick B^..D # re-apply commits B to D
git commit --amend --author="Your Name <correct@example.org>"
git cherry-pick E^..HEAD
git push --force-with-lease
```

[![asciicast](https://asciinema.org/a/fFMZzQOgJyfUf8HTnXyRj0v02.svg)](https://asciinema.org/a/fFMZzQOgJyfUf8HTnXyRj0v02)

0 comments on commit 6eb7f71

Please sign in to comment.