Small wording changes

This commit is contained in:
Richard Littauer 2018-11-29 14:12:07 -05:00
parent 42b5519891
commit 1877d108b0
1 changed files with 14 additions and 3 deletions

View File

@ -348,31 +348,42 @@ If you have made other commits in the meantime (i.e. the sensitive data is in a
<a href="i-need-to-change-the-content-of-a-commit-which-is-not-my-last"></a>
### I need to change the content of a commit which is not my last
Consider you created some (e.g. three) commits and later realise you missed doing something that belongs contextually into the first of those commits. This bothers you, because if you'd create a new commit containing those changes, you'd have a clean code base, but your commits weren't atomic (i.e. changes that belonged to each other weren't in the same commit). In such a situation you may want to change the commit where these changes belong to, include them and have the following commits unaltered. In such a case, git rebase might save you.
Consider you created some (e.g. three) commits and later realize you missed doing something that belongs contextually into the first of those commits. This bothers you, because if you'd create a new commit containing those changes, you'd have a clean code base, but your commits weren't atomic (i.e. changes that belonged to each other weren't in the same commit). In such a situation you may want to change the commit where these changes belong to, include them and have the following commits unaltered. In such a case, `git rebase` might save you.
Consider a situation where you want to change the third last commit you made.
```sh
(your-branch)$ git rebase -i HEAD~4
```
gets you into interactive rebase mode, which allows you to edit any of your last three commits. A text editor pops up, showing you something like
```sh
pick 9e1d264 The third last commit
pick 4b6e19a The second to last commit
pick f4037ec The last commit
```
which you change into
```sh
edit 9e1d264 The third last commit
pick 4b6e19a The second to last commit
pick f4037ec The last commit
```
This tells rebase that you want to edit your third last commit and keep the other two unaltered. Then you'll save (and close) the editor. git will then start to rebase. It stops on the commit you want to alter giving you the chance to edit that commit. Now you can apply the changes you missed applying when you initially commited that commit. You do so by editing and staging them. Afterwards you'll run```sh
This tells rebase that you want to edit your third last commit and keep the other two unaltered. Then you'll save (and close) the editor. Git will then start to rebase. It stops on the commit you want to alter, giving you the chance to edit that commit. Now you can apply the changes which you missed applying when you initially commited that commit. You do so by editing and staging them. Afterwards you'll run
```sh
(your-branch)$ git commit --amend
```
which tells `git` to recreate the commit, but to no edit the commit message. Having done that, the hard part is solved
which tells Git to recreate the commit, but to leave the commit message unedited. Having done that, the hard part is solved.
```sh
(your-branch)$ git rebase --continue
```
will do the rest of the work for you.