Odpowiedź @Mureinik jest dobra, ale dla początkującego niezrozumiała.
Pierwsza metoda:
- Jeśli chcesz tylko edytować najnowszą wiadomość zatwierdzenia, potrzebujesz tylko
git commit --amend, zobaczysz:
<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
#
- Jak widać, zatwierdzanie wiadomości u góry bez żadnego prefiksu polecenia, np.
pickJest to już strona edycji i można bezpośrednio edytować górną wiadomość oraz zapisać i wyjść , np .:
<your new correction commit message>
# Please enter the commit message for your changes. Lines starting
....
- Następnie zrób
git push -u origin master --forcelub <how you push normally> --force. Kluczem jest tutaj --force.
Druga metoda:
Możesz zobaczyć skrót zatwierdzenia przez git loglub wyciąg z adresu URL repozytorium, w moim przypadku jest to przykład881129d771219cfa29e6f6c2205851a2994a8835
Następnie możesz zrobić git rebase --interactive 881129d771219cfa29e6f6c2205851a2994a8835lub git rebase -i HEAD^(jeśli najnowsza)
Zobaczyłbyś:
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
- Ale jeśli widzisz
noop, to prawdopodobnie źle wpisujesz, np. Jeśli robisz to, git rebase -i 881129d771219cfa29e6f6c2205851a2994a88czego brakuje ^na końcu, lepiej zamknij edytor bez zapisywania i znajdź przyczynę:
noop
# Rebase 8db7e8b..fa20af3 onto 8db7e8b
...
- Jeśli nie ma
noopproblemu, po prostu zmień słowo pickna reword, inne po prostu pozostają (w tym momencie nie edytujesz komunikatu zatwierdzenia), np .:
reword <commit hash> <your current commit message>
# Rebase 8db7e8b..fa20af3 onto 8db7e8b
#
# Commands:
# p, pick = use commit
...
- Zapisz i wyjdź, zobaczy stronę edycji podobną do metody nr 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
#
- Edytuj wiadomość na górze, tak samo jak metoda nr 1 i zapisz i wyjdź, np .:
<your new correction commit message>
# Please enter the commit message for your changes. Lines starting
....
- Ponownie, tak samo jak metoda nr 1, wykonaj
git push -u origin master --forcelub <how you push normally> --force. Kluczem jest tutaj --force.
Aby uzyskać więcej informacji, przeczytaj dokument .