2014-05-09 16:48:06 +0000 2014-05-09 16:48:06 +0000
135
135

C'è un modo per modificare un messaggio di commit su GitHub?

C'è un modo per modificare un messaggio di commit dopo il commit e il push su GitHub? Vedo che c'è un ‘aggiungi una nota’ così come il commento in linea, ma nessuna modifica effettiva di un messaggio di commit. C'è anche “modificare il commit” nelle estensioni git, ma questo non modifica il messaggio esistente.

Risposte (5)

189
189
189
2014-05-10 10:27:44 +0000
  1. git rebase -i <commit hash you want to change>^

  2. Per ogni commit che volete cambiare il messaggio, cambiate pick in reword.

  3. Salva ed esci (in vi: :wq).

  4. Per ogni commit di questo tipo, avrai un editor per modificare il messaggio di commit. Cambialo come meglio credi, salva e chiudi.

  5. Ora puoi caricarli su github usando git push origin --force.

Se hai solo bisogno di sistemare il tuo ultimo commit, puoi sostituire i passi 1-4 con git commit --amend.

35
35
35
2018-06-18 09:49:45 +0000

In Intellij Idea puoi farlo facilmente.

  1. Aprire il Controllo di versione (Storia)
  2. Seleziona la scheda log
  3. Seleziona commit per cambiare il commento
  4. Premi F2 (Mac fn + F2), e aggiorna il tuo messaggio di commit
3
3
3
2019-03-14 07:29:36 +0000

Premessa:

se il tuo git-graph assomiglia a …

O target-commit that you want to change its message [df9c192]
|
O parent-commit [b7ec061]
|
O

(df9c192 e b7ec061 sono gli hash di commit di target-commit e parent-commit, separatamente)

Soluzione:

puoi semplicemente digitare le seguenti istruzioni…

git reset --soft b7ec061
git commit -m "your_new_description"
git push -f

Spiegazione:

  1. git reset --soft b7ec061 manterrà le tue modifiche ai file e ripristinerà il parent-commit (cioè b7ec061)
  2. git commit -m "..." creerà localmente un nuovo commit
  3. git push -f spingerà il tuo nuovo commit al server e sostituirà quello vecchio (es. df9c192)
2
2
2
2018-08-08 22:27:59 +0000

Un'altra opzione è quella di creare un ulteriore “errata commit” (e push) che fa riferimento all'oggetto commit che contiene l'errore – il nuovo errata commit fornisce anche la correzione. Un errata commit è un commit senza modifiche sostanziali al codice ma con un messaggio di commit importante – per esempio, aggiungi un carattere di spazio al tuo file readme e fai il commit di quel cambiamento con il messaggio di commit importante, o usa l'opzione git --allow-empty. È certamente più facile e sicuro del rebasing, non modifica la vera storia, e mantiene l'albero dei rami pulito (usare amend è anche una buona scelta se stai correggendo il commit più recente, ma un errata commit può essere una buona scelta per commit più vecchi). Questo tipo di cose accade così raramente che documentare semplicemente l'errore è abbastanza buono. In futuro, se hai bisogno di cercare in un log git una parola chiave di una caratteristica, il commit originale (errato) potrebbe non apparire perché la parola chiave sbagliata è stata usata in quel commit originale (il refuso originale) – comunque, la parola chiave apparirà nel commit errata che ti punterà al commit originale che aveva il refuso. Ecco un esempio:

$ git log commit 0c28141c68adae276840f17ccd4766542c33cf1d Author: First Last Date: Wed Aug 8 15:55:52 2018 -0600 Errata commit: This commit has no substantive code change. THis commit is provided only to document a correction to a previous commit message. This pertains to commit object e083a7abd8deb5776cb304fa13731a4182a24be1 Original incorrect commit message: Changed background color to red Correction (\*change highlighted\*): Changed background color to \*blue\* commit 032d0ff0601bff79bdef3c6f0a02ebfa061c4ad4 Author: First Last Date: Wed Aug 8 15:43:16 2018 -0600 Some interim commit message commit e083a7abd8deb5776cb304fa13731a4182a24be1 Author: First Last Date: Wed Aug 8 13:31:32 2018 -0600 Changed background color to red
0
0
0
2019-08-24 11:01:51 +0000

Risposta di @Mureinik è buono ma non comprensibile per i principianti.

Primo metodo:

  1. Se vuoi solo modificare l'ultimo messaggio di commit, allora ti basta git commit --amend, vedresti:
<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
#
  1. Come potete vedere, il messaggio di commit in alto senza alcun prefisso di comando come pick, questa è già la pagina di modifica e potete dirigere modificare il messaggio in alto e salvare e uscire, per esempio:
<your new correction commit message> 

# Please enter the commit message for your changes. Lines starting
....
  1. Poi fai git push -u origin master --force o <how you push normally> --force. La chiave qui è --force.

Secondo metodo:

  1. Puoi vedere l'hash di commit da git log o estrarre dall'url del repository, esempio nel mio caso è 881129d771219cfa29e6f6c2205851a2994a8835

  2. Poi puoi fare git rebase --interactive 881129d771219cfa29e6f6c2205851a2994a8835 o git rebase -i HEAD^ (se l'ultimo)

  3. Vedresti:

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
  1. Ma se vedi noop allora probabilmente stai scrivendo male, ad esempio se fai git rebase -i 881129d771219cfa29e6f6c2205851a2994a88 a cui manca ^ alla fine, ti conviene uscire dall'editor senza salvare e capire la ragione:
noop

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
...
  1. Se non c'è un problema di noop, allora cambia semplicemente la parola pick con reword, le altre rimangono (non si modifica il messaggio di commit a questo punto), ad es. g:
reword <commit hash> <your current commit message>

# Rebase 8db7e8b..fa20af3 onto 8db7e8b
#
# Commands:
# p, pick = use commit
...
  1. Save&quit vedrà la pagina di commit simile al metodo #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
#
  1. Modifica il messaggio in cima, come il metodo #1 e save&quit, ad esempio:
<your new correction commit message> 

# Please enter the commit message for your changes. Lines starting
....
  1. Ancora, come il metodo #1, fai git push -u origin master --force o <how you push normally> --force. La chiave qui è --force.

Per maggiori informazioni leggi il documento .