Il modo più semplice per farlo è utilizzare il comando rebase
.
Immaginate di avere questo repository:
$> git log --oneline
af28aeb Another test
a680317 Try something
d93792b Edit both files
f23cdbd Second commit add b
6f456bc First commit add a
Così avete fatto qualche prova con impegna af28aeb Another test
e a680317 Try something
. Vogliamo eliminarli dopo lo d93792b Edit both files
per pulire il repository.
Per fare che il comando sarà git rebase -i d93792b
Dove -i
è di indicare per entrare in modalità interattiva e d93792b
è il commettere hash dove vogliamo assorbire quello precedente.
Nota: nel caso in cui si desidera schiacciare tutti i commit come il primo, è necessario utilizzare git rebase --root -i
questo comando vi mostrerà che:
pick a680317 Try something
pick af28aeb Another test
# Rebase d93792b..af28aeb onto d93792b ( 2 TODO item(s))
#
# 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
Devi dire a rebase comando cosa vuoi fare. In tal caso, vi consiglio di riformulare il primo commit e squash la seconda come segue:
reword a680317 Try something
squash af28aeb Another test
# Rebase d93792b..af28aeb onto d93792b ( 2 TODO item(s))
#
# 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
Poi la modifica del testo sarà aperto per impostare il nuovo messaggio di commit.
Fix bug
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Tue Jul 28 08:40:04 2015 +0200
#
# rebase in progress; onto d93792b
# You are currently editing a commit while rebasing branch 'master' on 'd93792b'.
#
# Changes to be committed:
# new file: c
#
Ora si devono git commit --amend
e git rebase --continue
per completare il processo.
E il repository mostrerà come questo:
$> git log --oneline
5f98806 Fix bug
d93792b Edit both files
f23cdbd Second commit add b
6f456bc First commit add a
Che cosa si ottiene da 'git rev-parse maestro origine/master'?Sembra che prima di eseguire 'git reset' potresti aver scartato il tuo lavoro. Non preoccuparti se lo hai, come puoi trovarlo nel reflog ('git log -g'). – user3188445
Questo è ciò che ottengo: origine maestro $ git rev-parse/master 78c4e31d7f813a127603aa93d63eb2c9db8d7c47 78c4e31d7f813a127603aa93d63eb2c9db8d7c47 – anquegi
Okay, allora maestro è tornato su origin/master. E 'git diff' o' git diff --cached HEAD' mostra eventuali cambiamenti nel tuo albero o indice? In caso contrario, potrebbe essere necessario trovare il contenuto del master perso con 'git log -g'. – user3188445