2020-08-11 01:47:54 +02:00
|
|
|
# Fixing commits
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-16 16:03:51 +02:00
|
|
|
This is mostly from
|
2019-02-26 02:49:09 +01:00
|
|
|
[here](https://help.github.com/en/articles/changing-a-commit-message#rewriting-the-most-recent-commit-message).
|
2017-06-16 16:03:51 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
## Fixing the last commit
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
### Changing the last commit message
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-05-10 07:02:14 +02:00
|
|
|
1. `git commit --amend -m "New message"`
|
2017-06-21 21:01:10 +02:00
|
|
|
|
|
|
|
### Changing the last commit
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
1. Make your changes to the files
|
|
|
|
2. Run `git add <filename>` to add one file or `git add <filename1> <filename2> ...` to add multiple files
|
|
|
|
3. `git commit --amend`
|
|
|
|
|
|
|
|
## Fixing older commits
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
### Changing commit messages
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
1. `git rebase -i HEAD~5` (if, for example, you are editing some of the last five commits)
|
|
|
|
2. For each commit that you want to change the message, change `pick` to `reword`, and save
|
|
|
|
3. Change the commit messages
|
|
|
|
|
|
|
|
### Deleting old commits
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
1. `git rebase -i HEAD~n` where `n` is the number of commits you are looking at
|
|
|
|
2. For each commit that you want to delete, change `pick` to `drop`, and save
|
|
|
|
|
|
|
|
## Squashing commits
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
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. Change `pick` to `squash` on the lines containing the commits you want to squash and save
|
|
|
|
|
|
|
|
## Reordering commits
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2017-06-21 21:01:10 +02:00
|
|
|
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
|
|
|
|
|
2017-06-21 21:06:09 +02:00
|
|
|
## Pushing commits after tidying them
|
2021-08-20 22:54:08 +02:00
|
|
|
|
2021-08-20 21:53:28 +02:00
|
|
|
1. `git push origin +my-feature-branch` (Note the `+` there and substitute your actual branch name.)
|