Antwoord van @Mureinik ](https://superuser.com/a/751909/248836) is goed, maar niet begrijpelijk voor newbie.
Eerste methode:
- Als je alleen het laatste commit bericht wilt bewerken, dan heb je alleen
git commit --amend nodig, dan zou je zien:
<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
#
- Zoals je kunt zien, staat het commit bericht bovenaan zonder enig voorvoegsel van commando’s zoals
pick, dit is al de bewerk pagina en je kunt bewerk het bovenste bericht en opslaan&beëindigen direct uitvoeren, b.v.:
<your new correction commit message>
# Please enter the commit message for your changes. Lines starting
....
- Doe dan
git push -u origin master --force of <how you push normally> --force. De sleutel hier is --force.
Tweede methode:
Je kunt de commit hash zien door git log of uit de repository url te halen, voorbeeld in mijn geval is 881129d771219cfa29e6f6c2205851a2994a8835
Dan kun je git rebase --interactive 881129d771219cfa29e6f6c2205851a2994a8835 doen of git rebase -i HEAD^ (als het de nieuwste is)
Je zou zien:
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
- Maar als je
noop ziet, dan typ je waarschijnlijk verkeerd, bijv. als je git rebase -i 881129d771219cfa29e6f6c2205851a2994a88 doet en er mist ^ aan het eind, dan kun je beter de editor afsluiten zonder op te slaan en de reden uitzoeken:
noop
# Rebase 8db7e8b..fa20af3 onto 8db7e8b
...
- Als er geen
noop probleem is, dan verander je gewoon het woord pick in reword , andere blijft gewoon staan (je bewerkt de commit boodschap op dit punt niet), bijv. bijv:
reword <commit hash> <your current commit message>
# Rebase 8db7e8b..fa20af3 onto 8db7e8b
#
# Commands:
# p, pick = use commit
...
- Save&quit zal de edit pagina laten zien, gelijk aan methode #1:
<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
#
- Edit de boodschap bovenaan, gelijk aan methode #1 en save&quit, bijv:
<your new correction commit message>
# Please enter the commit message for your changes. Lines starting
....
- Nogmaals, gelijk aan methode #1, doe
git push -u origin master --force of <how you push normally> --force. De sleutel hier is --force.
Voor meer info lees de doc .