Antwort von @Mureinik ist gut aber für Neulinge nicht nachvollziehbar.
Erste Methode:
- Wenn Sie nur die letzte Commit-Nachricht bearbeiten möchten, benötigen Sie nur Folgendes
git commit --amend:
<your existing commit mesage foo bar>
# Please enter the commit message fir your changes. Lines starting
# with # will be ignored, and an empty message aborts the commit.
#
# Date: Sat Aug 24 17:56:16 2019 +0800
#
# On branch is up to date with 'origin/master'.
#
# changes to be committed:
# modified: foo.py
#
- Wie Sie sehen können, schreiben Sie die Nachricht oben ohne das Präfix eines Befehls fest, zum Beispiel
pick, dies ist bereits die Bearbeitungsseite, und Sie können die oberste Nachricht direkt bearbeiten und speichern und beenden , zB:
<your new correction commit message>
# Please enter the commit message for your changes. Lines starting
....
- Dann mach
git push -u origin master --forceoder <how you push normally> --force. Der Schlüssel ist hier --force.
Zweite Methode:
Sie können den Commit-Hash sehen git logoder aus der Repository-URL extrahieren, in meinem Fall zum Beispiel881129d771219cfa29e6f6c2205851a2994a8835
Dann können Sie tun git rebase --interactive 881129d771219cfa29e6f6c2205851a2994a8835oder git rebase -i HEAD^(wenn die neueste)
Du würdest sehen:
pick <commit hash> <your current commit message>
# Rebase 8db7e8b..fa20af3 onto 8db7e8b
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
- Aber wenn Sie
noopdann sehen, dass Sie wahrscheinlich falsch tippen, z. B. wenn Sie git rebase -i 881129d771219cfa29e6f6c2205851a2994a88das Fehlen ^am Ende tun , sollten Sie den Editor ohne Speichern verlassen und den Grund herausfinden:
noop
# Rebase 8db7e8b..fa20af3 onto 8db7e8b
...
- Wenn es kein
noopProblem gibt, ändern Sie einfach das Wort pickin reword. Anderes bleibt erhalten (Sie bearbeiten die Commit-Nachricht an dieser Stelle nicht). Beispiel:
reword <commit hash> <your current commit message>
# Rebase 8db7e8b..fa20af3 onto 8db7e8b
#
# Commands:
# p, pick = use commit
...
- Beim Speichern und Beenden wird die Bearbeitungsseite angezeigt , die Methode 1 ähnelt:
<your existing commit mesage foo bar>
# Please enter the commit message fir your changes. Lines starting
# with # will be ignored, and an empty message aborts the commit.
#
# Date: Sat Aug 24 17:56:16 2019 +0800
#
# interactive rebase in progress; onto b057371
# Last command done (1 command done):
# reword d996ffb <existing commit message foo bar>
# No commands remaining.
# You are currently editing a commit while rebasing branch 'master' on 'b057371'.
#
# changes to be committed:
# modified: foo.py
#
- Bearbeiten Sie die Nachricht wie bei Methode 1 oben und speichern und beenden Sie sie, z. B .:
<your new correction commit message>
# Please enter the commit message for your changes. Lines starting
....
- Wieder das gleiche wie Methode # 1,
git push -u origin master --forceoder <how you push normally> --force. Der Schlüssel ist hier --force.
Weitere Informationen finden Sie in der Dokumentation .