mirror of https://github.com/zulip/zulip.git
docs: Add instructions for git commit --fixup to change older commits.
Zulip PRs often have multiple commits and review process requires contributors to make changes to the code in other commits than just the latest one, which requires more familiarity with git rebase than most other tasks. `git commit --fixup` with `git rebase -i --autosquash` is probably the most direct and efficient way specifically for this task, so it seems useful to have a recommendation about it.
This commit is contained in:
parent
d3b5a76a67
commit
f2dce683e5
|
@ -40,6 +40,30 @@ Sometimes, you want to make one commit out of a bunch of commits. To do this,
|
|||
1. `git rebase -i HEAD~n` where `n` is the number of commits you are interested in
|
||||
2. Reorder the lines containing the commits and save
|
||||
|
||||
## Changing code in an older commit
|
||||
|
||||
If your pull request has multiple commits, a reviewer may request changes that require
|
||||
you to make changes to an older commit than the latest one. This tends to be more tedious
|
||||
than just amending the last commit and there can be various approaches, but the most efficient
|
||||
is by using `git commit --fixup`:
|
||||
|
||||
1. Make your changes to the files and stage them, as usual.
|
||||
1. Identify the hash of the commit you want to modify - for example by copying it from
|
||||
`git log --oneline`.
|
||||
1. Commit your changes as a fixup, by using `git commit --fixup <hash of the commit>`.
|
||||
1. A new commit with its message starting with `fixup!` has been created. Now you can
|
||||
run `git rebase -i --autosquash HEAD~n`, replacing `n` with the number of commits
|
||||
to include in the rebase, as in the other sections. In the interactive
|
||||
view the commits will be automatically ordered appropriately so that the fixups get
|
||||
squashed into the corresponding commits.
|
||||
1. (Optional) If you want to avoid having to include `--autosquash` every time, you
|
||||
can add the following configuration to your `~/.gitconfig`:
|
||||
|
||||
```
|
||||
[rebase]
|
||||
autosquash = true
|
||||
```
|
||||
|
||||
## Pushing commits after tidying them
|
||||
|
||||
1. `git push origin +my-feature-branch` (Note the `+` there and substitute your actual branch name.)
|
||||
|
|
Loading…
Reference in New Issue