Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'doc/topics/git/useful_git_commands.md')
-rw-r--r--doc/topics/git/useful_git_commands.md34
1 files changed, 33 insertions, 1 deletions
diff --git a/doc/topics/git/useful_git_commands.md b/doc/topics/git/useful_git_commands.md
index 22548be2e8b..e4c106e3e33 100644
--- a/doc/topics/git/useful_git_commands.md
+++ b/doc/topics/git/useful_git_commands.md
@@ -59,6 +59,38 @@ git revert <commit-sha>
git commit --amend
```
+### Create a new message for older commits
+
+WARNING:
+Changing commit history can disrupt others' work if they have cloned, forked, or have active branches.
+Only amend pushed commits if you're sure it's safe.
+To learn more, see [Git rebase and force push](git_rebase.md).
+
+```shell
+git rebase -i HEAD~n
+```
+
+Replace `n` with the number of commits you want to go back.
+
+This opens your text editor with a list of commits.
+In the editor, replace `pick` with `reword` for each commit you want to change the message:
+
+```shell
+reword 1fc6c95 original commit message
+pick 6b2481b another commit message
+pick 5c1291b another commit message
+```
+
+After saving and closing the file, you can update each message in a new editor window.
+
+After updating your commits, you must push them to the repository.
+As this rewrites history, a force push is required.
+To prevent unintentional overwrites, use `--force-with-lease`:
+
+```shell
+git push --force-with-lease
+```
+
### Add a file to the last commit
```shell
@@ -213,4 +245,4 @@ questions that you know someone might ask.
Each scenario can be a third-level heading, for example `### Getting error message X`.
If you have none to add when creating a doc, leave this section in place
-but commented out to help encourage others to add to it in the future. -->
+but commented out to help encourage others to add to it in the future. --> \ No newline at end of file