Domanda

Sto cercando un comando git che mi aiuti con i miei rami di funzionalità quando saranno pronti per passare a Master.Questo comando git comprimerebbe tutte le mie modifiche sul mio ramo in un unico commit sopra master.Lo faccio oggi con:

git rebase origin/master
git rebase -i HEAD~4

Dove 4 è il numero di commit da schiacciare.Tuttavia, questo richiede che io sappia quanti commit ho.Lo faccio oggi eseguendo:

git log HEAD...origin/master

e poi contare i commit.

Sento che dovrebbe esserci un modo migliore per farlo.Oppure è così che fanno anche tutti gli altri?

È stato utile?

Soluzione

Tutto quello che devi fare è:

git checkout feature_branch
git rebase master
git checkout master
git merge --squash feature_branch

Come il documenti per git merge --squash Dire:

Produci l'albero di lavoro e lo stato dell'indice come se fosse avvenuta una vera fusione (ad eccezione delle informazioni sulla fusione), ma non effettuare effettivamente un commit o spostare l'HEAD, né registrare $GIT_DIR/MERGE_HEAD per far sì che il successivo comando git commit crei una fusione commettere.Ciò ti consente di creare un singolo commit sopra il ramo corrente il cui effetto è lo stesso dell'unione di un altro ramo (o più nel caso di un polipo).

Dopodiché puoi git commit le modifiche già predisposte.

Altri suggerimenti

Ecco cosa faccio, raccolto da molta esperienza lavorando in squadre più grandi:

# Get latest from master
git checkout master
git pull --rebase

# rebase master into your feature branch
git checkout feature/my-feature
git rebase master --preserve-merges

# merge feature into master
git checkout master

# DO ONLY ONE of the 2 options below
# if you only have one or (maybe) 2 commits in your feature branch
git merge feature/my-feature

# OR
# this forces an empty merge commit (useful if we need to roll things back)
git merge --no-ff feature/my-feature

# if you use Github, this should also close the pull request
git push origin master
.

Spero che questo aiuti!

Penso che tu stia cercando git merge --squash.Dovrebbe portare il commit dal tuo filiale di funzionalità nel maestro e schiacciarli, in modo da poter creare un singolo commit.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top