diff --git a/snippets/update-commit-contents.md b/snippets/update-commit-contents.md new file mode 100644 index 000000000..5e3c1e438 --- /dev/null +++ b/snippets/update-commit-contents.md @@ -0,0 +1,21 @@ +--- +title: Edit the last commit +tags: commit,beginner +--- + +Updates the last commit's contents without changing its message. + +- Use `git commit --amend --no-edit` to add any staged changes to the last commit, without changing its message. + +```sh +git commit --amend --no-edit +``` + +```sh +git add . +git commit -m "Fix the network bug" +# Edit or add files +git add . +git commit --amend --no-edit +# The last commit includes the edited/added files +``` diff --git a/snippets/update-commit-message.md b/snippets/update-commit-message.md new file mode 100644 index 000000000..df7211752 --- /dev/null +++ b/snippets/update-commit-message.md @@ -0,0 +1,19 @@ +--- +title: Change the last commit's message +tags: commit,beginner +--- + +Updates the last commit's message without changing its contents. + +- Use `git commit --amend -m ` to replace the last commit's message with the new ``. + +```sh +git commit --amend -m +``` + +```sh +git add . +git commit -m "Fix the newtork bug" +git commit --amend -m "Fix the network bug" +# The last commit's message is now "Fix the network bug" +```