Make amend commands more specific (#218)

Previously, this document the same command for "I wrote the wrong thing in a commit message" and "I need to add staged changes to the previous commit". These are different operations! Now, the former has a command that only changes the commit message (without adding staged changes), and the latter has commands to add staged changes with or without updating the commit message.

I also added "reword" and "extend" aliases to the sample gitconfig for using the two pieces of `git commit --amend` separately.
This commit is contained in:
David Glasser 2018-10-23 05:24:26 -07:00 committed by Richard Littauer
parent 83261c5b7a
commit 1eb620d54c
1 changed files with 12 additions and 4 deletions

View File

@ -170,15 +170,15 @@ $ git show <commitid>:filename
### I wrote the wrong thing in a commit message ### I wrote the wrong thing in a commit message
If you wrote the wrong thing and the commit has not yet been pushed, you can do the following to change the commit message: If you wrote the wrong thing and the commit has not yet been pushed, you can do the following to change the commit message without changing the changes in the commit:
```sh ```sh
$ git commit --amend $ git commit --amend --only
``` ```
This will open your default text editor, where you can edit the message. On the other hand, you can do this all in one command: This will open your default text editor, where you can edit the message. On the other hand, you can do this all in one command:
```sh ```sh
$ git commit --amend -m 'xxxxxxx' $ git commit --amend --only -m 'xxxxxxx'
``` ```
If you have already pushed the message, you can amend the commit and force push, but this is not recommended. If you have already pushed the message, you can amend the commit and force push, but this is not recommended.
@ -312,9 +312,15 @@ Note: the parent number is not a commit identifier. Rather, a merge commit has a
```sh ```sh
(my-branch*)$ git commit --amend (my-branch*)$ git commit --amend
``` ```
If you already know you don't want to change the commit message, you can tell git to reuse the commit message:
```sh
(my-branch*)$ git commit --amend -C HEAD
```
<a name="commit-partial-new-file"></a> <a name="commit-partial-new-file"></a>
### I want to stage part of a new file, but not the whole file ### I want to stage part of a new file, but not the whole file
@ -1390,11 +1396,13 @@ On OS X and Linux, your git configuration file is stored in ```~/.gitconfig```.
d = diff d = diff
dc = diff --changed dc = diff --changed
ds = diff --staged ds = diff --staged
extend = commit --amend -C HEAD
f = fetch f = fetch
loll = log --graph --decorate --pretty=oneline --abbrev-commit loll = log --graph --decorate --pretty=oneline --abbrev-commit
m = merge m = merge
one = log --pretty=oneline one = log --pretty=oneline
outstanding = rebase -i @{u} outstanding = rebase -i @{u}
reword = commit --amend --only
s = status s = status
unpushed = log @{u} unpushed = log @{u}
wc = whatchanged wc = whatchanged