Come eseguire git rebase del primo commit

Cerca

Eseguire il rebase del primo ed unico commit del nostro repository git può essere effettivamente una cosa poco chiara se non si è abituati, perché la classica sintassi git rebase -i HEAD~3 che siamo abituati per estrarre per esempio gli ultimi tre commit ci restituirà un fastidioso e frustrante noob error. Per eseguire il rebase del primo commit, dobbiamo ricorrere a questa specifica sintassi di git:

				
					git rebase -i --root
				
			

Questo comando apre l’editor di default mostrandoci l’unico commit presente più o meno in questo modo:

				
					pick f7fde4a Change the commit message but push the same commit
# Rebase 9fdb3bd..f7fde4a onto 9fdb3bd
#
# 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
#
# 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
				
			

A questo punto, rimpiaziamo la parola chiave pick con reword, salviamo il file e chiudiamolo. Ci verrà presentato un nuovo editor più o meno così:

				
					We have changed this line with the new commit message
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Tue Apr 11 14:25:10 2023 +0200
#
# interactive rebase in progress; onto 89081ee
# Last command done (1 command done):
#    reword f7fde4a Change the commit message but push the same commit.
# No commands remaining.
# You are currently editing a commit while rebasing branch 'master' on '89081ee'.
#
#
# Initial commit
#
# Changes to be committed:
#       new file:   marker_generator/Dockerfile
				
			

A questo punto siamo pronti per eseguire il push e sovrascrivere il vecchio commit utilizzando questo comando:

				
					git push --force
				
			

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.

Most Recent

Come installare Borg su Synology NAS

Installare Borg su Synology NAS è cosa molto semplice da realizzare in quanto è possibile farlo mediante il package rilasciato da SynoCommunity. Vediamo in questa

Partners