L'opzione --squash
-git merge
potrebbe essere utile ed è disponibile in git 1.4.1 e successive. Questo mette in scena gli effetti di un'unione, ma non crea un commit. Quindi, se 143eff
è la più antica commit che si desidera includere nel schiacciato commit, la filiale corrente è master
e il "solo un mese fa" commit è dcb7e5
, si potrebbe fare:
# Save the old position of "master" by creating a branch old-master:
$ git checkout master
$ git branch old-master
# Create and checkout a branch called "new-master" that's at the old commit:
$ git checkout -b new-master 143eff
# Stage the effects of merging the "one month ago" commit:
$ git merge --squash dcb7e5
Updating 143eff3..dcb7e5b
Fast-forward
Squash commit -- not updating HEAD
[... status output showing the staged changes ..]
# Create the squashed commit:
$ git commit -m "A commit squashing history up to a month ago"
# (You could use --amend if you want them to be squashed into 143eff
# instead of being a commit after that.)
Ora è possibile controllare con git diff dcb7e5 new-master
che sono davvero gli stessi.
Avanti, si vuole rebase il resto del tuo lavoro sulla nuova-master:
$ git rebase --onto new-master dcb7e5 master
che vi lascerà un ricalcolato master
che dovrebbe avere la storia che si desidera. la storia (in questo caso, è possibile controllare questo con git diff old-master master
e git log
Quando si spinge master per GitHub è necessario aggiungere --force
visto che hai riscritto:.
# Push master to github, with "--force", since you've rewritten history:
$ git push --force origin master
È ora possibile rimuovere new-master
, che è alla zucca commettere, con:
git branch -d new-master
Apparentemente github corre git gc --auto
su spinte, così si dovrebbe vedere un po 'di salvaspazio presto ...
fonte
2010-07-28 11:55:10
possibile duplicato di [Come combinare i primi due commit di un repository Git?] (Http://stackoverflow.com/questions/435646/how-do-i-combine-the-first-two-commits- of-a-git-repository) Mentre la domanda collegata qui parla di combinare solo due commit, le ricette descritte funzionano anche per ulteriori commit. –
Grazie Pavel. Lo guarderò. – dugla
Vuoi schiacciare tutti quei commit in un commit, o vuoi davvero scartare le modifiche che sono state introdotte? Sulla base dei tuoi commenti che vuoi "scartare" e il progetto sta andando in una direzione diversa, non è del tutto chiaro per me. – masonk