2015-07-28 37 views
8

Ho bisogno di mettere tutti i miei commit in uno solo chiamato snapshot iniziale, al fine di rilasciarlo in un Github Repo, so che per farlo seguo thisSquash tutti i tuoi commit in uno, prima di una richiesta pull in github

la mia prima domanda è che voglio condividere con un repository esterni e questo dico:

una parola di cautela: fare solo questo su commit che non sono stati spinti un repository esterna . Se altri hanno basato il lavoro fuori dal commit che si sta per eliminare, è possibile che si verifichino molti conflitti. Non scrivere solo se è stato condiviso con altri.

e ciò che accade voglio mettere tutte le mie impegna in una sola, come fare questo:

ho trovato anche questo:

# Switch to the master branch and make sure you are up to date. 
git checkout master 
git fetch # this may be necessary (depending on your git config) to receive updates on origin/master 
git pull 

# Merge the feature branch into the master branch. 
git merge feature_branch 

# Reset the master branch to origin's state. 
git reset origin/master 

# Git now considers all changes as unstaged changes. 
# We can add these changes as one commit. 
# Adding . will also add untracked files. 
git add --all 
git commit 

ma non succede nulla:

$ git reset origin/master 
$ git add --all 
$ git commit -m "initial snapshot" 
On branch master 
Your branch is up-to-date with 'origin/master'. 
nothing to commit, working directory clean 
+0

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

+0

Questo è ciò che ottengo: origine maestro $ git rev-parse/master 78c4e31d7f813a127603aa93d63eb2c9db8d7c47 78c4e31d7f813a127603aa93d63eb2c9db8d7c47 – anquegi

+0

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

risposta

18

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 
Problemi correlati